code_file1
stringlengths
80
4k
code_file2
stringlengths
91
4k
similar_or_different
int64
0
1
#include<iostream> #include<sstream> #include<algorithm> #include<climits> #include<cmath> #include<cstdio> #include<cstdlib> #include<ctime> #include<cfloat> #include<functional> #include<map> #include<string> #include<cstring> #include<vector> #include<queue> #include<stack> #include<deque> #include<set> #include<bitset> #include<list> #include<numeric> #include<complex> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> i_i; typedef pair<long long, int> ll_i; typedef pair<double, int> d_i; typedef pair<long long, long long> ll_ll; typedef pair<double, double> d_d; typedef vector<int> Vint; #define PI 3.141592653589793238462643383279 #define mod 1000000007LL #define rep(i, n) for(i = 0;i < n;++i) #define rep1(i, n) for(i = 1;i < n;++i) #define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j) #define per(i, n) for(i = n - 1;i > -1;--i) #define int(x) int x; scanf("%d",&x) #define int2(x, y) int x, y; scanf("%d%d",&x, &y) #define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z) #define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z) #define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z) #define scn(n, a) rep(i, n)cin >> a[i] #define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i] #define pri(x) cout << x << "\n" #define pri2(x, y) cout << x << " " << y << "\n" #define pri3(x, y, z) cout << x << " " << y << " " << z << "\n" #define pb push_back #define mp make_pair #define all(a) (a).begin(),(a).end() #define endl "\n" #define kabe puts("---------------------------") #define kara puts("") #define debug(x) cout << " --- " << x << "\n" #define debug2(x, y) cout << " --- " << x << " " << y << "\n" #define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n" #define X first #define Y second #define eps 0.0001 #define prid(x) printf("%.15lf\n", x) signed main(void){ int i, j, k; for(int testcase = 0;testcase >= 0;testcase++){ int3(m, nin, nax); if(!(m|nax|nin))break; int p[m]; scn(m, p); int res = 0, resi; nin--; nax--; for(i = nin;i <= nax;++i){ if(res <= p[i] - p[i + 1]){ res = p[i] - p[i + 1]; resi = i + 1; } } pri(resi); //*/ //*/ break; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ while(1){ int m,l,r; cin>>m>>l>>r; if(!m&&!l&&!r)break; int a[300]; for(int i=0;i<m;i++)cin>>a[i]; sort(a,a+m); reverse(a,a+m); int gap=0,n; for(int i=l-1;i<r;i++) if(a[i]-a[i+1]>=gap)n=i,gap=a[i]-a[i+1]; cout <<n+1<<endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; // type alias typedef long long LL; typedef pair<int,int> II; typedef tuple<int,int,int> III; typedef vector<int> VI; typedef vector<string> VS; typedef unordered_map<int,int> MAPII; typedef unordered_set<int> SETI; template<class T> using VV=vector<vector<T>>; // minmax template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; } template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; } // repetition #define FORE(i,a,b) for(int i=(a);i<=(b);++i) #define REPE(i,n) for(int i=0;i<=(n);++i) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) for(int i=0;i<(n);++i) #define FORR(x,arr) for(auto& x:arr) #define SZ(a) int((a).size()) // collection #define ALL(c) (c).begin(),(c).end() // DP #define MINUS(dp) memset(dp, -1, sizeof(dp)) #define ZERO(dp) memset(dp, 0, sizeof(dp)) // stdout #define println(args...) fprintf(stdout, ##args),putchar('\n'); // debug cerr template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; } void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; } template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); } template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; } #define __KUMATRACE__ true #ifdef __KUMATRACE__ #define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); } #define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; } #define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); } #else #define dump(args...) #define dumpc(ar) #define dumpC(beg,end) #endif // $ cp-batch SequenceGrowingEasy | diff SequenceGrowingEasy.out - // $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address SequenceGrowingEasy.cpp && ./a.out /* 4/7/2020 9:39- */ const int MAX_N=1e6+1; LL A[MAX_N]; int N; void nope() { cout<<-1<<endl; exit(0); } void solve() { REP(i,N) if(A[i]>i) nope(); LL res=0; int l=0; while(l<N) { int r=l; while(r+1<N&&A[r+1]>A[r]) ++r; if(A[r]-A[l]==r-l) { // dump(l,r,r-l,A[r]); res+=A[r]; } else { nope(); } l=r+1; } cout<<res<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout<<setprecision(12)<<fixed; cin>>N; REP(i,N) cin>>A[i]; solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; std::vector<long long> trips; int ans=0; cin>>n; trips.resize(n); for(auto &x:trips) cin>>x; n = trips.size(); for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ for(int k=j+1;k<n;k++){ if(trips[i]!=trips[j] && trips[i]!=trips[k] && trips[j]!=trips[k]) if(trips[i]+trips[j]>trips[k] && trips[i]+trips[k]>trips[j] && trips[j]+trips[k]>trips[i]) ans++; } } } cout << ans; 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>; using V = vector<int>; int main(int argc, char const *argv[]) { int n; cin >> n; int a, b = 0; long long int ans = 0; rep(i,n) { cin >> a; if (a>b) b = a; else ans += b-a; } cout << ans << endl; return 0; }
/************************************* * problem: AT2164 Rabbit Exercise. * user ID: 63720. * user name: Jomoo. * time: 2019-08-14. * language: C++. * upload place: Luogu. *************************************/ #include <bits/stdc++.h> using namespace std; #define puts_return(x) { puts(x); return 0; } #define write_return(x) { write(x); return 0; } typedef signed char int8; typedef unsigned char uint8; typedef short int16; typedef unsigned short uint16; typedef int int32; typedef unsigned uint32; typedef long long int64; typedef unsigned long long uint64; template <typename Int> inline Int read() { Int flag = 1; char c = getchar(); while ((!isdigit(c)) && c != '-') c = getchar(); if (c == '-') flag = -1, c = getchar(); Int init = c & 15; while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15); return init * flag; } template <typename Int> inline void write(Int x) { if (x < 0) putchar('-'), x = ~x + 1; if (x > 9) write(x / 10); putchar((x % 10) | 48); } template <typename Int> inline void write(Int x, char nextch) { write(x); putchar(nextch); } uint64 n, m, k; vector<int32> x, a, to, ans; vector<bool> vis; int main() { n = read<uint64>(); x.resize(n); to.resize(n); ans.resize(n); vis.resize(n); for (size_t i = 0; i < n; i++) x[i] = read<int32>(), to[i] = i; for (size_t i = n - 1; i > 0; i--) x[i] -= x[i - 1]; m = read<uint64>(); a.resize(m); k = read<uint64>(); for (auto num : a) num = read<int32>(), swap(to[num], to[num - 1]); for (size_t i = 0; i < n; i++) if (!vis[i]) { vector<int32> s; for (int j = i; !vis[j]; j = to[j]) s.push_back(j), vis[j] = true; for (size_t j = 0; j < s.size(); j++) ans[s[j]] = x[s[(j + k) % s.size()]]; } // ans[0] = x[0]; // ans[n - 1] = x[n - 1]; int64 tot = 0; for (auto answer : ans) write(tot += answer, 10); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int N, x[100]; cin >> N; if (N == 0) { cout << '0'; return 0; } for (int i = 0; i < 100; i++) { x[i] = 0; } for (int i = 0; N != 0; i++, N -= N & 1, N /= -2) { x[i] = N & 1; } int foo = 99; for (; x[foo] == 0; foo--); for (; foo >= 0; foo--) { cout << x[foo]; } return 0; }
#include <iostream> #include <map> #include <algorithm> #include <vector> #include <iomanip> #include <sstream> #include <cmath> #include <math.h> #include <string> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string a = ""; while( n != 0 ) { int r = n % 2; if( r == -1 ) r = 1; a += r + '0'; n = ( n - r ) / ( -2 ); } reverse( a.begin() , a.end() ); if( a == "" ) cout << '0'; else cout << a; }
1
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype> #include <cmath> #include <string> #include <vector> #include <set> #include <map> #include <queue> #include <algorithm> #include <utility> #include <deque> #include <stack> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<char> vc; typedef vector<ll> vl; typedef queue<int> qi; typedef queue<ll> ql; typedef pair<ll,ll> pll; typedef pair<int,ll> pil; typedef pair<ll,int> pli; #define rep(i,n) for (int i=0;i<n;i++) #define mp make_pair #define pb push_back #define pf push_front #define F first #define S second #define INF 200000009 class DSU{ public: int fa[200005]; inline void init(){ for (int i=0;i<200005;++i) fa[i]=i; } inline int f(int x){ return fa[x]==x? x:fa[x]=f(fa[x]); } inline void u(int x,int y){ x=f(x);y=f(y); if (x==y) return; fa[x]=y; } inline bool same(int x,int y){ return (f(x)==f(y)); } }dsu; typedef pair<ll,pii> Edge; vector<Edge> edges; ll a[200005];ll d; int n; inline void solve(int l,int r){ if (l==r) return; if (l==r-1){ edges.pb(mp(a[l]+a[r]+d,mp(l,r))); return; } int m=(l+r)>>1; solve(l,m);solve(m+1,r); int bestl,bestr; ll mincostl=1e18; for (int i=l;i<=m;++i){ if (a[i]-d*i<mincostl){ mincostl=a[i]-d*i;bestl=i; } } ll mincostr=1e18; for (int i=m+1;i<=r;++i){ if (a[i]+d*i<mincostr){ mincostr=a[i]+d*i;bestr=i; } } for (int i=l;i<=m;++i){ edges.pb(mp(mincostr+a[i]-d*i,mp(i,bestr))); } for (int i=m+1;i<=r;++i){ edges.pb(mp(mincostl+a[i]+d*i,mp(bestl,i))); } return; } int main(){ ios::sync_with_stdio(false); cin>>n>>d; for (int i=1;i<=n;++i) cin>>a[i]; if (n==1){ cout<<0<<endl;return 0; } solve(1,n); sort(edges.begin(),edges.end());// smaller to bigger reverse(edges.begin(),edges.end());// bigger to smaller dsu.init(); ll ans=0; while(!edges.empty()){ Edge E=edges.back();edges.pop_back(); ll u=E.S.F,v=E.S.S,cost=E.F; if (dsu.same(u,v)) continue; dsu.u(u,v); ans+=cost; } cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; int n, k; double kitaichi(vector<int> p, int start, int k){ double ans; for (int i = 0; i < k; i++){ double sum = 0; for (int j = 1; j <= p[start+i]; j++){ sum += j; } ans += sum/p[start+i]; } return ans; } int main() { cin >> n >> k; vector<int> p(n); for (int i = 0; i < n; i++){ cin >> p.at(i); } int sum = 0; int start; int s = 0; for (int i = 0; i < 1; i++){ for (int j = 0; j < k; j++){ s += p.at(i+j); } sum = s; start = i; } for (int i = 1; i + k <= n; i++){ s += p.at(i+k-1); s -= p.at(i-1); if (sum < s){ sum = s; start = i; } } cout << fixed << setprecision(15) << kitaichi(p, start, k) << endl; }
0
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) #define REP(i,n) for (int64_t i=0; i<(n); ++i) #define P pair<int,int> using ll=int64_t; using namespace std; #define ketasuu(n) fixed<<setprecision(n) #define btoe(p) p.begin(),p.end() #define etob(p) p.rbegin(),p.rend() int main(){ int a,b; cin>>a>>b; string s; cin>>s; bool ok=true; rep(i,a){ if(s[i]-'0'>=0 && s[i]-'0'<=9){ }else{ ok=false; } } if(s[a]!='-') ok=false; for(int i=a+1; i<a+b+1; ++i) { if(s[i]-'0'>=0 && s[i]-'0'<=9){ }else{ ok=false; } } cout<<(ok?"Yes":"No")<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { string A, B, S; cin >> A >> B >> S; cout << ((regex_match(S, regex("\\d{" + A + "}-\\d{" + B + "}"))) ? "Yes" : "No") << "\n"; }
1
#include<bits/stdc++.h> using namespace std; using ll = long long; double per(double n){ if(n == 1) return n; return n*per(n-1); } int main(){ int n; cin >> n; vector<pair<int, int>>p(n); for(int i=0;i<n;i++){ int x, y; cin >> x >> y; p[i] = {x, y}; } double ans = 0; sort(p.begin(), p.end()); do{ for(int i=0;i<n;i++){ if(i){ ans += sqrt((p[i].first-p[i-1].first)*(p[i].first-p[i-1].first)+(p[i].second-p[i-1].second)*(p[i].second-p[i-1].second)); } } }while(next_permutation(p.begin(), p.end())); ans /= per((double)n); printf("%.9lf\n", ans); }
#include"bits/stdc++.h" using namespace std; #define ll long long #define mod 1000000007 #define prec(n) fixed<<setprecision(n) int N; int x[10], y[10]; double dist(int i, int j) { double dx = x[i] - x[j]; double dy = y[i] - y[j]; return pow(dx * dx + dy * dy, 0.5); } void solve() { cin >> N; for(int i = 1; i <= N; i++) cin >> x[i] >> y[i]; double dsum = 0.0; for (int i = 1 ;i<=N; ++i) { for (int j = i+1; j<=N;++j) { dsum += dist(i, j) * 2 / N; } } cout << prec(10) << dsum << "\n"; return; } int main() { solve(); return 0; }
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; int main(){ int N,K; cin >> N >> K; vector<int> A(N); for(int i=0;i<N;i++) cin >> A.at(i); for(int k=0;k<K;k++){ vector<int> B(N+1,0); for(int i=0;i<N;i++){ int left = max(0,i-A.at(i)); int right = min(i+A.at(i)+1,N); B.at(left) ++; B.at(right) --; } for(int i=1;i<=N;i++){ B.at(i) += B.at(i-1); } if(A==B) break; A = B; } for(int i=0;i<N;i++){ cout << A.at(i) << endl; } }
1
/* Simplicity and Goodness */ #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> using namespace std; // using namespace __gnu_pbds; // typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; void my_dbg() { cout << endl; } template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) { cout << ' ' << A; my_dbg(B...); } #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__) #define scn(n) scanf("%d", &n) #define lscn(n) scanf("%lld", &n) #define pri(n) printf("%d ", (int)(n)) #define prin(n) printf("%d\n", (int)(n)) #define lpri(n) printf("%lld ", n) #define lprin(n) printf("%lld\n", n) #define rep(i,a,b) for(int i=a; i<(int)b; i++) #define pb push_back #define mp make_pair #define F first #define S second using ll = long long; using vi = vector<int>; using vl = vector<ll>; const int inf = INT_MAX; const int ninf = INT_MIN; const int mod = 1e9+7; const int maxN = 1e6+2; int main() { string s; cin >> s; int l = -2, r = -2; for(int i = 0; i + 1 < (int) s.size(); i ++) { if(s[i] == s[i + 1]) { l = i, r = i + 1; break; } } for(int i = 0; i + 2 < (int) s.size(); i ++) { set<char> unique; for(int j = i; j < i + 3; j ++) { unique.insert(s[j]); } if((int) unique.size() <= 2) { l = i, r = i + 2; break; } } printf("%d %d\n", l + 1, r + 1); }
#include <iostream> #include <cmath> #include <vector> #include <map> #include <iomanip> #include <algorithm> #include <sstream> #include <string> #include <math.h> #include <set> using namespace std; typedef long long ll; int main() { string s; cin >> s; for ( int i = 0 ; i < s.length()-1 ; i++ ) { if ( s[i] == s[i+1] ) { cout << i + 1 << ' ' << i + 2; return 0; } else if ( s[i] == s[i+2] ) { cout << i + 1 << ' ' << i + 3; return 0; } } cout << -1 << ' ' << -1; }
1
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < n; ++i) #define P pair<ll, ll> #define Graph vector<vector<ll>> #define fi first #define se second constexpr ll mod = 1000000007; constexpr ll INF = (1ll << 60); constexpr double pi = 3.14159265358979323846; template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { ll n; cin >> n; vector<pair<string, ll>> st; rep(i, n) { string s; cin >> s; st.push_back({s, 1}); } ll m; cin >> m; rep(i, m) { string s; cin >> s; st.push_back({s, -1}); } sort(st.begin(), st.end()); // rep(i, n + m) { cout << st[i].fi << endl; } ll ans = 0, cnt = 0; rep(i, n + m) { if (st[i].fi == st[i + 1].fi) { cnt += st[i].se; } else { cnt += st[i].se; // cout << cnt << endl; chmax(ans, cnt); cnt = 0; } if (i == n + m - 1 && cnt != 0) chmax(ans, cnt); } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define _GLIBCXX_DEBUG int main() { int n, m; cin >> n; vector<string> vec_n(n); rep(i, n) cin >> vec_n[i]; cin >> m; vector<string> vec_m(100); rep(i, m) cin >> vec_m[i]; int max = -100; rep(i, n){ int cnt = 0; rep(j, n){ if(vec_n[i] == vec_n[j]) cnt++; } rep(j, m){ if(vec_n[i] == vec_m[j]) cnt--; } if(cnt > max) max = cnt; } if(max < 0){ cout << 0 << endl; }else cout << max << endl; }
1
#include <iostream> #include <vector> #include <string> using namespace std; const vector<char> ss = {'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', '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 main () { int n; while (cin >> n, n) { vector<int> v(n); for (auto &i : v) cin >> i; string str; cin >> str; for (int i = 0; i < str.size(); i++) { int t = (str[i] - (('a' <= str[i] && str[i] <= 'z') ? 'a' : ('A' - 26)) - v[i % n] + 52) % 52; cout << ss[t]; } cout << endl; } return 0; }
#include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <map> #include <set> #include <functional> #include <cassert> typedef long long ll; using namespace std; #define debug(x) cerr << #x << " = " << x << endl; #define mod 1000000007 //1e9+7(prime number) #define INF 1000000000 //1e9 #define LLINF 2000000000000000000LL //2e18 #define SIZE 100010 bool solve(){ int n; int k[SIZE]; char c[SIZE]; scanf("%d",&n); if(n == 0) return false; for(int i=0;i<n;i++){ scanf("%d",k+i); } scanf("%s",c); for(int i=0;c[i]!='\0';i++){ for(int j=0;j<k[i%n];j++){ if(c[i] == 'a') c[i] = 'Z'; else if(c[i] == 'A') c[i] = 'z'; else c[i]--; } } printf("%s\n",c); return true; } int main(){ while(solve()); return 0; }
1
#include <iostream> #include <algorithm> #define INF (2 << 28) using namespace std; int main(){ int n, m, cost[101][101]; while(cin >> n >> m, n||m){ fill_n(*cost, 101*101, INF); for(int i = 1; i <= n; i++) cost[i][i] = 0; while(m--){ int k; cin >> k; if(k == 0){ int a, b; cin >> a >> b; cout << (cost[a][b] == INF ? -1 : cost[a][b]) << endl; } else { int a, b, c; cin >> a >> b >> c; cost[a][b] = cost[b][a] = min(cost[a][b], c); for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ cost[i][j] = min(cost[i][j], cost[i][a] + cost[a][b] + cost[b][j]); cost[i][j] = min(cost[i][j], cost[i][b] + cost[b][a] + cost[a][j]); } } } } } }
#include <bits/stdc++.h> using namespace std; void read(int &x){ char ch=getchar();x=0; for (;ch==' '||ch=='\n';ch=getchar()); for (;ch!=' '&&ch!='\n';x=x*10+ch-'0',ch=getchar()); } void write(int x){ if (x>9) write(x/10); putchar(x%10+'0'); } int n,m,ans=2e9,SUM,dis[17][17],num[33000],dp[33000][17]; int main(){ read(n),read(m); for (int i=0;i<m;i++){ int x,y,c;read(x),read(y),read(c);SUM+=c; dis[x-1][y-1]=dis[y-1][x-1]=c; } for (int i=1;i<(1<<n);i++){ int cnt; for (int j=0;j<n;j++) if ((1<<j)&i){ cnt=j;break; } num[i]=num[i^(1<<cnt)]; for (int k=0;k<n;k++) if ((1<<k)&i) num[i]+=dis[k][cnt]; } for (int i=0;i<33000;i++) for (int j=0;j<17;j++)dp[i][j]=-5e8; dp[1][0]=0; for (int i=1;i<(1<<n);i++){ for (int j=0;j<n;j++){ for (int k=0;k<n;k++) if ((i&(1<<j))>0 && (i&(1<<k))>0 && dis[j][k]) dp[i][j]=max(dp[i][j],dp[i^(1<<j)][k]+dis[j][k]); for (int k=i;k>=0;k=(k-1)&i){ if (k&(1<<j)) dp[i][j]=max(dp[i][j],dp[i^k|(1<<j)][j]+num[k]); if (k==0) break; } } if ((1<<(n-1))&i) ans=min(ans,SUM-dp[i][n-1]); } write(ans); }
0
#include <bits/stdc++.h> #include <sys/types.h> #include <unistd.h> #define _overload(_1,_2,_3,name,...) name #define _rep(i,n) _range(i,0,n) #define _range(i,a,b) for(int i=int(a);i<int(b);++i) #define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__) #define _rrep(i,n) _rrange(i,n,0) #define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i) #define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__) #define _all(arg) begin(arg),end(arg) #define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg)) #define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary) #define clr(a,b) memset((a),(b),sizeof(a)) #define bit(n) (1LL<<(n)) #define popcount(n) (__builtin_popcountll(n)) using namespace std; template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;} template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;} using ll=long long; using R=long double; const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7 inline int sgn(const R& r){return(r > EPS)-(r < -EPS);} inline R sq(R x){return sqrt(max(x,0.0L));} template<typename T> vector<T> make_vector(size_t sz){ return vector<T>(sz); } template<typename T,typename... Ts> auto make_vector(size_t sz, Ts... ts){ return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...)); } template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value!=0>::type fill_value(U &u, const V... v){ u=U(v...); } template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value==0>::type fill_value(U &u, const V... v){ for(auto &e:u){ fill_value<T>(e,v...); } } const int dx[8]={1,0,-1,0,1,-1,-1,1}; const int dy[8]={0,1,0,-1,1,1,-1,-1}; const pid_t pid = getpid(); // Problem Specific Parameter: ll solve(const vector<ll> &ary){ vector<ll> a = ary; const int n = ary.size(); const int m = 60; int c = 0; rep(i, n - 1){ int pivot = i; for(; c < m; ++c){ int cmax = 0; rep(k, i, n) { const int bit = (a[k] >> (m - 1 - c)) & 1; if(chmax(cmax, bit)) pivot = k; } if(cmax > 0) break; } if(c == m) break; if(pivot != i) swap(a[i], a[pivot]); rep(k, i + 1, n){ const int flag = (a[k] >> (m - 1 - c)) & 1; if(flag) a[k] ^= a[i]; } c++; } ll ret = 0LL; rep(i, n) if((ret^a[i]) > ret) ret ^= a[i]; return ret; } int main(void){ int n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; ll xorsum = 0LL; rep(i, n) xorsum ^= a[i]; const int m = 60; rrep(j, m){ const int bit = (xorsum >> j) & 1; if(bit == 0) continue; rep(i, n) if(a[i] >> j & 1) a[i] ^= (1LL << j); } const ll amax = solve(a); const ll bmax = xorsum ^ amax; cout << amax + bmax << endl; return 0; }
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<iomanip> #include<math.h> #include<complex> #include<queue> #include<deque> #include<stack> #include<map> #include<set> #include<bitset> #include<functional> #include<assert.h> #include<numeric> using namespace std; typedef pair<int,int> P; typedef long long ll; typedef long double ld; const int inf=1e9+7; const ll longinf=1LL<<60; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) #define F first #define S second const int mx=1000010; const ll mod=1e9+7; int main(){ int n; string s; cin >> n >> s; int q; cin >> q; while(q--){ int k; cin >> k; ll ans = 0; ll dcnt = 0; ll mcnt = 0; ll cnt = 0; rep(i,n){ if(i-k>=0){ if(s[i-k]=='D'){ dcnt--; cnt-=mcnt; } if(s[i-k]=='M'){ mcnt--; } } if(s[i]=='C'){ ans+=cnt; continue; } if(s[i]=='M'){ cnt+=dcnt; mcnt++; continue; } if(s[i]=='D'){ dcnt++; continue; } } cout << ans << endl; } return 0; }
0
#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; const int MAX_N = 1005; int id[MAX_N][MAX_N],A[MAX_N][MAX_N],dp[MAX_N*MAX_N]; bool visit[MAX_N*MAX_N],calc[MAX_N*MAX_N]; vector<int> G[MAX_N*MAX_N]; void init() { rep(i,MAX_N) { rep(j,MAX_N) { id[i][j] = -1; } } rep(i,MAX_N*MAX_N) { dp[i] = 1; visit[i] = false; calc[i] = false; } return; } int getid(int a, int b) { if (a > b) swap(a,b); return id[a][b]; } int dfs(int n) { //cout << "visiting:" << n << endl; if (visit[n]) { //cout << "b"; if (!calc[n]) return -1; return dp[n]; } visit[n] = true; int res; rep(i,G[n].size()) { res = dfs(G[n][i]); if (res == -1) { //cout << "c"; return -1; } dp[n] = max(dp[n],res+1); } calc[n] = true; //cout << "return:" << dp[n] << endl; return dp[n]; } int main() { init(); int N; cin >> N; int cnt = 0; rep(i,N) { rep(j,N-1) { int idx = i+1; cin >> A[i][j]; if (getid(idx,A[i][j]) == -1) { if (idx > A[i][j]) id[A[i][j]][idx] = cnt; else id[idx][A[i][j]] = cnt; cnt++; } if (j > 0) { G[getid(idx,A[i][j-1])].push_back(getid(idx,A[i][j])); } } } /* rep(i,N) { rep(j,N) { if (i == j) cout << " "; else cout << getid(i+1,j+1) << " "; } cout << endl; } rep(i,N) { rep(j,G[i].size()) { cout << G[i][j] << " "; } cout << endl; } */ int ans = 0; rep(i,N*(N-1)/2) { int res = dfs(i); if (res == -1) { cout << "-1" << endl; return 0; } ans = max(ans,res); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define mset(a, b) memset(a, b, sizeof(a)) #define mcpy(a, b) memcpy(a, b, sizeof(a)) using namespace std; typedef long long LL; const int N = 505; const int P = 8005; template <typename T> inline void read(T &AKNOI) { T x = 0, flag = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') flag = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); } AKNOI = flag * x; } int n, pr[P], pcnt, vis[P]; LL a[N][N], mx; //set<LL> S; LL gcd(LL x, LL y) { return (!y)? x : gcd(y, x % y); } inline LL lcm(LL x, LL y) { if (!x || !y) return x + y; return x / gcd(x, y) * y; } void init() { read(n); if (n == 2) { printf("4 7\n23 10\n"); exit(0); } for (int i = 2; i <= 8000; ++i) { if (!vis[i]) { pr[++pcnt] = i; } for (int j = 1; j <= pcnt && i * pr[j] <= 8000; ++j) { vis[i * pr[j]] = 1; if (i % pr[j]) continue; } } } void solve() { for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { if (!((i + j) & 1)) { a[i][j] = pr[(i + j) / 2] * pr[(n - i + 1 + j) / 2 + n / 2]; } } } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { if ((i + j) & 1) { a[i][j] = lcm(lcm(a[i - 1][j], a[i + 1][j]), lcm(a[i][j - 1], a[i][j + 1])) + 1; } printf("%lld ", a[i][j]); /*mx = max(mx, a[i][j]); if (S.find(a[i][j]) != S.end()) { printf("error\n"); } S.insert(a[i][j]);*/ } printf("\n"); } //printf("%lld\n", mx); } int main() { init(); solve(); return 0; }
0
#include <iostream> #include<vector> #include<algorithm> #include<map> #include<iomanip> #include<set> #include<queue> #include<deque> #include<iomanip> #include<sstream> #include<cmath> #include<bitset> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define req(i,n) for(int i = 1;i <= n; i++) #define rrep(i,n) for(int i = n -1;i >= 0;i--) #define ALL(obj) begin(obj), end(obj) typedef long long int ll; typedef long double ld; const ll INF = (1 << 29); ll k, m, n,h,w,v; const ll MOD= 1000000007; const ld PI = acos(-1); template<typename A, size_t N, typename T> void Fill(A(&array)[N], const T & val) { std::fill((T*)array, (T*)(array + N), val); } int main() { cin >> n; ll sum = 1; vector<int> a(n + 1), c(3, 0); req(i, n) cin >> a[i]; req(i, n) { ll cnt = 0, id = -1; if (a[i] == c[0]) { cnt++; id = 0; } if (a[i] == c[1]) { cnt++; id = 1; } if (a[i] == c[2]) { cnt++; id = 2; } if (id == -1) { cout << 0 << endl; return 0; }sum *= cnt; c[id]++; sum %= MOD; }cout << sum << endl; }
#include <algorithm> #include <climits> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <vector> #include <iostream> // https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a class modint { private: static constexpr long long int MOD = 1000000000 + 7; // (10 ** 9) + 7 long long int x; static long long int sanitize(long long int n) { while (n < 0) { n += modint::MOD; } return n % modint::MOD; } public: modint(long long int x) : x(sanitize(x)) {} modint() : x(0) {} modint &operator=(const modint &other) { this->x = other.x; return *this; } modint operator+(const modint &other) const { modint ret; ret.x = (this->x + other.x) % modint::MOD; return ret; } modint operator-(const modint &other) const { modint ret; ret.x = (this->x - other.x); if (x < 0) { ret.x += modint::MOD; } return ret; } modint operator*(const modint &other) const { modint ret; ret.x = (this->x * other.x) % modint::MOD; return ret; } modint &operator+=(const modint &other) { this->x = (this->x + other.x) % modint::MOD; return *this; } modint operator<<(const long long int shift) const { modint base = modint(2).pow(shift); return *this * base; } modint pow(long long int n) const { modint ret; ret.x = _pow(n); return ret; } friend std::ostream &operator<<(std::ostream &stream, const modint &value); private: long long int _pow(long long int n) const { long long int a = this->x; long long res = 1; while (n > 0) { if (n & 1) { res = res * a % modint::MOD; } a = a * a % modint::MOD; n >>= 1; } return res; } }; std::ostream &operator<<(std::ostream &stream, const modint &value) { return stream << value.x; } #define int long long int constexpr int INF = std::numeric_limits<int>::max(); constexpr int NINF = std::numeric_limits<int>::min(); using namespace std; void solve() { int N; cin >> N; vector<int> v(N+1); v[0] = 3; modint ans = 1; for (int i = 0; i < N; i++) { int a; cin >> a; ans = ans * v[a]; v[a]--; v[a+1]++; } cout << ans << endl; } signed main() { cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; }
1
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (n) ; i++) constexpr auto INF = 2147483647; typedef long long ll; struct Node{ int key; Node *right, *left, *parent; }; //property Node *root, *NIL; void Insert(int k){ Node *y = NIL; Node *x = root; Node *z; z= new Node; z ->key = k; z ->left = NIL; z ->right = NIL; while(x != NIL){ y = x; if(z->key < x->key) x= x->left; else x = x-> right; } z->parent =y; if(y == NIL) root = z; else { if(z->key < y->key) y->left = z; else y->right = z; } } Node* Find(int k){ Node *x = root; while (x != NIL){ if(x->key == k) break; else if (k < x->key) x = x->left; else x = x->right; } return x; } //return minimum key node under x Node* TreeMinimum(Node* x){ while(x->left != NIL) x= x->left; return x; } // Node* TreeSuccessor(Node* x){ if(x->right!= NIL)return TreeMinimum(x->right); Node* y = x->parent; while( y != NIL && x== y->right){ x= y; y = y->parent; } return y; } void Delete(Node* z){ Node* y; // Delete comp Node* x; // child if(z->left == NIL || z->right ==NIL) y = z; else y = TreeSuccessor(z); if(y->left != NIL) x = y->left; else x= y-> right; if(x != NIL) x->parent = y->parent; if(y == y->parent->left) y->parent->left = x; else y->parent->right = x; if(y != z) z->key = y->key; free(y); } void Inorder(Node *r){ if(r == NIL) return; Inorder(r->left); cout << " " << r->key; Inorder(r->right); } void Preorder(Node *r){ if(r == NIL) return; cout << " " << r->key; Preorder(r->left); Preorder(r->right); } int main(){ int m, k; string com; cin >> m; rep(i,m){ cin >> com; if(com == "print"){ Inorder(root); cout << endl; Preorder(root); cout << endl; }else{ cin >> k; if (com == "insert"){ Insert(k); }else if(com == "find"){ Node* u = Find(k); if(u != NIL) cout << "yes" << endl; else cout << "no" << endl; }else if(com == "delete"){ Delete(Find(k)); } } } return 0; }
#include<iostream> #include<vector> #include<algorithm> using namespace std; int gcd(int a,int b){ while(b){ a%=b; swap(a,b); } return a; } int main(){ int n; cin>>n; vector<int> line(n); for(int i=0;i<n;++i){ cin>>line[i]; } int man = line[0]; for(int i=1;i<n;++i){ man = gcd(man,line[i]); } vector<int> front; vector<int> back; for(int i=1;i*i<=man;++i){ if(i*i==man){ front.push_back(i); break; } if(man%i==0){ front.push_back(i); back.push_back(man/i); } } for(int i=0;i<front.size();++i){ cout<<front[i]<<endl; } for(int i=back.size()-1;i>=0;--i){ cout<<back[i]<<endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { long long i,j,k,a,b,c=0,d=0,n,m,t; cin>>a>>b>>c>>d; n=min(a,b); m=min(c,d); cout<<n+m; return 0; }
#include <cstdio> #include <cstring> #include <vector> #include <algorithm> using namespace std; int main() { static char str[1200000]; int len; vector<pair<char, int> > x; scanf("%s", str); len = strlen(str); x.reserve(len); for(int i = 0; i < len; ++i) { int it = i + 1; while(it < len && str[it] == str[i]) ++it; x.push_back(make_pair(str[i], it - i)); i = it - 1; } int ans = 0; for(int i = 0; i < (int)x.size() - 2; ++i) { pair<char, int> jjj = x[i], ooo = x[i + 1], iii = x[i + 2]; if(jjj.first != 'J' || ooo.first != 'O' || iii.first != 'I') continue; if(ooo.second > jjj.second || ooo.second > iii.second) continue; ans = max(ans, min(min(jjj.second, ooo.second), iii.second)); } printf("%d\n", ans); return 0; }
0
#include <stdio.h> #include <string.h> int main (){ char a[100]; char b[100]; char c[100]; scanf("%s %s %s", a, b, c); int A = strlen(a); int B = strlen (b); for (int i = 0; i < 10; i++){ if ( a[A - 1] == b[0] && b[B - 1]== c[0]){ puts ("YES"); break; } else{ puts ("NO"); break; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; using P = pair<int,string>; int main() { string a,b,c; cin >> a >> b >>c ; if(a.back() == b.front() && b.back() == c.front()) cout <<"YES" << endl; else cout << "NO" << endl; }
1
#include <bits/stdc++.h> typedef long long int ll; typedef long double ld; #define pb push_back #define pii pair < int , int > #define F first #define S second #define int long long #define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #pragma GCC optimize ("Ofast") using namespace std; /// khodaya komak kon /// ya navid navid const int N=2e5+100; ll seg[4*N]; void shift(ll nod){ if (seg[nod]==1){ seg[nod*2]=1; seg[nod*2+1]=1; } } void upd(ll nod,ll l,ll r,ll L,ll R){ if (l>=R || L>=r){ return ; } if (l>=L && r<=R){ seg[nod]=1; return ; } shift(nod); ll mid=(r+l)/2; upd(nod*2,l,mid,L,R); upd(nod*2+1,mid,r,L,R); } ll get(ll nod,ll l,ll r,ll id){ if (r-l==1){ return seg[nod]; } shift(nod); ll mid=(r+l)/2; if (mid>id){ return get(nod*2,l,mid,id); } else{ return get(nod*2+1,mid,r,id); } } ll k; vector <pii> h; ll st[N]; ll fn[N]; vector <int> g[N]; ll cnt=0; ll par[N]; vector <int> t; ll par1[N]; ll dfs(ll v,ll p,ll hi){ par1[v]=p; t.pb(v); ll z=t.size(); z-=k; z=max((ll)0,z); par[v]=t[z]; h.pb({hi,v}); st[v]=cnt; for (int i=0;i<g[v].size();i++){ ll u=g[v][i]; if (u==p){ continue; } cnt++; dfs(u,v,hi+1); } t.pop_back(); fn[v]=cnt; } int32_t main(){ sync; ll n; cin >> n >> k; ll ans=0; ll x; cin >> x; if (x!=1){ ans++; } for (int i=2;i<=n;i++){ cin >> x; g[x].pb(i); g[i].pb(x); } upd(1,0,N,0,1); dfs(1,1,0); sort(h.begin(),h.end()); reverse(h.begin(),h.end()); for (int i=0;i<n-1;i++){ ll v=h[i].S; ll u=par[v]; //cout << v << " " << u << endl; ll z=get(1,0,N,st[v]); if (z==1 || par1[u]==1){ continue; } ans++; upd(1,0,N,st[u],fn[u]+1); } cout << ans; }
#include <bits/stdc++.h> #define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++) #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) // const bool debug=true; const bool debug=false; #define DEBUG if(debug==true) #define vprint(x) for(auto a:(x)) cout << x << endl; #define all(x) begin((x)), end((x)) using namespace std; typedef long long ll; typedef unsigned long long ull; const ll MOD = 1000000007; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true;} return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true;} return false; } vector<ll> a; ll n,m,v,p; bool chk(int idx) { if (a[idx]+m<a[n-p]) { return false; } ll cnt = 0; rep(i,n) { if (i>n-p||i<=idx) { cnt += m; } else { cnt += max(0LL, a[idx]+m-a[i]); } } return cnt >= m*v; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); cin>>n>>m>>v>>p; a.assign(n,0); rep(i,n) cin>>a[i]; sort(all(a)); ll l=0,r=n-1; while(r>l) { ll mid = (l+r)/2; if (chk(mid)) { r = mid; } else { l = mid; } if (l+1==r) { if (chk(l)) { r = l; } else { l = r; } } } cout << n-l << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; #define x first #define y second #define mp make_pair #define pb push_back template <typename TYPE> inline void chkmax(TYPE &x,TYPE y){x<y?x=y:0;} template <typename TYPE> inline void chkmin(TYPE &x,TYPE y){y<x?x=y:0;} template <typename TYPE> void readint(TYPE &x) { x=0;int f=1;char c; for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1; for(;isdigit(c);c=getchar())x=x*10+c-'0'; x*=f; } const int MAXN=300005; int n,s,a[MAXN]; ll ans=0,b[MAXN]; int dir=-1; void work(int l,int r) { if(a[l]>s)ans+=a[r]-s; else if(a[r]<s)ans+=s-a[l]; else if(b[l]>=b[r]) { if(dir!=0)ans+=a[r]-a[l],dir=0; b[l]+=b[r]; work(l,r-1); } else { if(dir!=1)ans+=a[r]-a[l],dir=1; b[r]+=b[l]; work(l+1,r); } } int main() { #ifndef ONLINE_JUDGE // freopen("code.in","r",stdin); // freopen("code.out","w",stdout); #endif readint(n),readint(s); for(int i=1;i<=n;++i)readint(a[i]),readint(b[i]); work(1,n); printf("%lld\n",ans); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < int(n); i++) #define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--) #define reps(i, n) for (int i = 1; i <= int(n); i++) #define rreps(i, n) for (int i = int(n); i >= 1; i--) #define repc(i, n) for (int i = 0; i <= int(n); i++) #define rrepc(i, n) for (int i = int(n); i >= 0; i--) #define repi(i, a, b) for (int i = int(a); i < int(b); i++) #define repic(i, a, b) for (int i = int(a); i <= int(b); i++) #define each(x, y) for (auto &x : y) #define all(a) (a).begin(), (a).end() #define bit(b) (1ll << (b)) #define uniq(v) (v).erase(unique(all(v)), (v).end()) #define rsort(v) sort(all(v)); reverse(all(v)) using namespace std; using i32 = int; using i64 = long long; using f80 = long double; using vi32 = vector<i32>; using vi64 = vector<i64>; using vf80 = vector<f80>; using vstr = vector<string>; inline void yes() { cout << "Yes" << '\n'; exit(0); } inline void no() { cout << "No" << '\n'; exit(0); } inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); } inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; } void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; } template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {}; template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {}; template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; } template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; } template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; } template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; } void solve() { int N, X; cin >> N >> X; vi64 S(N); vector<tuple<i64, i64, i64>> t; i64 M = 0; i64 D = 0; i64 ok = 0, ng = -1; rep(i, N) { i64 b, l, u; cin >> b >> l >> u; t.push_back(make_tuple(b, l, u)); S[i] = b * l + (X - b) * u; M += S[i]; ok += b; D += -l * b; } vi32 ord(N); iota(all(ord), 0); sort(all(ord), [&](int i, int j) { return S[i] > S[j]; }); vi64 sums(N + 1); rep(i, N) sums[i + 1] = sums[i] + S[ord[i]]; while (ok - ng > 1) { i64 k = (ok + ng) / 2; i64 ma = -1e18; i64 p = k / X, q = k - p * X; rep(i, N) { i64 MM; if (p > i) MM = sums[p + 1] - S[ord[i]]; else MM = sums[p]; i64 b, l, u; tie(b, l, u) = t[ord[i]]; i64 T; if (q <= b) T = q * l; else T = b * l + (q - b) * u; amax(ma, MM + T); } if (ma + D >= 0) ok = k; else ng = k; } cout << ok << '\n'; }
0
/** * @copyright (c) 2020 Daisuke Hashimoto */ #include <bits/stdc++.h> using namespace std; using ll = int64_t; using Pair = pair<int64_t, int64_t>; // std::cout << std::setprecision(20) << 1.1 << endl; int main() { cin.tie(0); ios::sync_with_stdio(false); int64_t K, T; cin >> K >> T; vector<int64_t> A(T); for (int64_t i = 0; i < T; ++i) { cin >> A[i]; } sort(A.begin(), A.end()); reverse(A.begin(), A.end()); cout << max(A[0] - (K - A[0] + 1), 0L) << endl; return 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<ll,ll>; //マクロ //forループ関係 //引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか //Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) //xにはvectorなどのコンテナ #define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい #define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく #define MAX(x) *max_element(ALL(x)) //最大値を求める #define MIN(x) *min_element(ALL(x)) //最小値を求める //定数 #define INF 1000000000000 //10^12:極めて大きい値,∞ #define inf 2,147,483,647 //int値の最大値 #define MOD 1000000007 //10^9+7:合同式の法 #define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用) //略記 #define PB push_back //vectorヘの挿入 #define MP make_pair //pairのコンストラクタ #define F first //pairの一つ目の要素 #define S second //pairの二つ目の要素 #define cint(n) int n;cin>>n; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } int gcd(int a, int b) { if (b==0) return a; else return gcd(b, a%b); } int lcm(int a, int b) { return a * b / gcd(a, b); } int main() { int n,x;cin>>n>>x; vector<int> a(n); rep(i,n){ cin>>a[i]; } sort(ALL(a)); int j=0; ll sum=0; while(sum<x && j<n){ sum+=a[j]; j++; } if(sum==x){ cout<<j; }else{ cout<<j-1; } return 0; }
0
#include<bits/stdc++.h> using namespace std; #define ft ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ll long long string s,p; int main() { ft ll t,i,j,n,m=0,l,r; cin>>s; n=s.size(); for(i=0;i<n;i++) { if((i+1)<n && s[i]==s[i+1]) { cout<<(i+1)<<" "<<(i+2)<<"\n"; return 0; } else if(((i+2)<n && s[i]==s[i+2])) { cout<<(i+1)<<" "<<(i+3)<<"\n"; return 0; } } cout<<"-1 -1\n"; return 0; }
/* Simplicity and Goodness */ #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> using namespace std; // using namespace __gnu_pbds; // typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; void my_dbg() { cout << endl; } template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) { cout << ' ' << A; my_dbg(B...); } #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__) #define scn(n) scanf("%d", &n) #define lscn(n) scanf("%lld", &n) #define pri(n) printf("%d ", (int)(n)) #define prin(n) printf("%d\n", (int)(n)) #define lpri(n) printf("%lld ", n) #define lprin(n) printf("%lld\n", n) #define rep(i,a,b) for(int i=a; i<(int)b; i++) #define pb push_back #define mp make_pair #define F first #define S second using ll = long long; using vi = vector<int>; using vl = vector<ll>; const int inf = INT_MAX; const int ninf = INT_MIN; const int mod = 1e9+7; const int maxN = 1e6+2; int main() { string s; cin >> s; int l = -2, r = -2; for(int i = 0; i + 1 < (int) s.size(); i ++) { if(s[i] == s[i + 1]) { l = i, r = i + 1; break; } } for(int i = 0; i + 2 < (int) s.size(); i ++) { set<char> unique; for(int j = i; j < i + 3; j ++) { unique.insert(s[j]); } if((int) unique.size() <= 2) { l = i, r = i + 2; break; } } printf("%d %d\n", l + 1, r + 1); }
1
#include <iostream> #include <vector> #include <algorithm> using namespace std; const int INF = 99999999; int main(void) { int e, t; vector<int> y2, z3; for (t = 0; t*t <= 1000000; t++) y2.push_back(t*t); for (t = 0; t*t*t <= 1000000; t++) z3.push_back(t*t*t); while (cin >> e, e) { int m = INF; for (int i = 0; i < y2.size(); i++) { for (int j = 0; j < z3.size(); j++) { if (y2[i]+z3[j] <= e) { m = min(m, (e-y2[i]-z3[j])+i+j); } } } cout << m << endl; } return 0; }
#include <iostream> using namespace std; int main() { int e; while (scanf("%d", &e) != EOF && e) { int m = 1000; for (int z=100; z>=0; z--) { if (e < z*z*z) { continue; } for (int y=0; y<m; y++) { if (e < y*y + z*z*z) { break; } int x = e - y*y - z*z*z; if (x + y + z < m) { m = x + y + z; } } } printf("%d\n", m); } }
1
#include <bits/stdc++.h> using namespace std; int main() { int N, M, point = 0, max = 0; cin >> N; vector<string> blue(N); set<string> ch; for (int i = 0; i < N; ++i) { cin >> blue.at(i); ch.insert(blue.at(i)); } cin >> M; vector<string> red(M); for (int i = 0; i < M; ++i) { cin >> red.at(i); ch.insert(red.at(i)); } for (auto x : ch) { point = 0; //重要 for (int i = 0; i < N; ++i) { if (blue.at(i) == x) { ++point; } } for (int i = 0; i < M; ++i) { if (red.at(i) == x) { --point; } } max = max < point ? point : max; } cout << max << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n, m, ans = 0; cin >> n; map<string, int> s; map<string, int> t; for (int i = 0; i < n; i++) { string blue; cin >> blue; s[blue]++; } cin >> m; for (int i = 0; i < m; i++) { string red; cin >> red; t[red]++; } for (auto i = s.begin(); i != s.end(); i++) { ans = max(ans, i->second - t[i->first]); } cout << ans << endl; }
1
#include<stdio.h> int main() { int N,R,A; scanf("%d %d", &N, &R); A =100*(10-N); if(N>=10){ printf("%d", R); } else{ printf("%d", R + A); } return 0; }
#include<iostream> using namespace std; long long int MOD = 1000000007; long long modpow(long long a, long long n, long long mod); long long modinv(long long a, long long mod); int main() { //A int n, r; cin >> n >> r; if (n >= 10) { cout << r << endl; } else { cout << r + 100 * (10 - n) << endl; } return 0; //B /*int n; cin >> n; int k; cin >> k; int i = 0; while (n > 0) { n = (int)(n / k); i++; } cout << i << endl; return 0;*/ //C /*int n; cin >> n; int x[100]; int i; for (i = 0; i < n; i++) { cin >> x[i]; } int sum, j, summin = 100000000; for (i = 0; i <= 100; i++) { sum = 0; for (j = 0; j < n; j++) { sum = sum + (x[j] - i) * (x[j] - i); } if (sum < summin)summin = sum; } cout << summin << endl; return 0; */ //D /* long long int n; cin >> n; long long int a, b; cin >> a >> b; if (n == 2) { cout << 0 << endl; return 0; } long long int sum = 1; int i; long long int x = 2, m = n; //2^nを計算 while (m > 0) { if (m % 2 == 1) { sum = (sum * x) % MOD; } m = (int)(m / 2); x = (x * x) % MOD; } //cout << 1 << endl; long long int sum1 = 1; for (i = 1; i <= a; i++) { sum1 = (sum1 * (n + 1 - i)) % MOD; } for (i = 1; i <= a; i++) { sum1 = (sum1 * modinv(i, MOD)) % MOD; } sum = (sum - sum1 + MOD) % MOD; //cout << 2 << endl; sum1 = 1; for (i = 1; i <= b; i++) { sum1 = (sum1 * (n + 1 - i)) % MOD; } for (i = 1; i <= b; i++) { sum1 = (sum1 * modinv(i, MOD)) % MOD; } sum = (sum - sum1 + MOD) % MOD; sum = (sum + MOD - 1) % MOD; cout << sum << endl; return 0; */ } // a^n mod を計算する long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // a^{-1} mod を計算する long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }
1
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; int main() { ll N, x; cin >> N >> x; vector<ll> a(N); rep(i,N) cin >> a.at(i); ll ans = 0; rep(i,N) { if (i == 0) continue; if(a.at(i) + a.at(i-1) > x) { ll diff = a.at(i) + a.at(i-1) - x; ans += diff; if (diff <= a.at(i)) a.at(i) -= diff; else a.at(i) = 0; } } cout << ans << endl; }
#include<bits/stdc++.h> #include<cctype> using namespace std; #define rep(i,n) for (int i=0;i<(n);i++) #define all(v) (v).begin(),(v).end() typedef long long int ll; #define pi 3.1415926535897932384 #define E9 1000000000 #define eps 1e-4 #define pii pair<int,int> int main(){ ll N; cin >> N; ll a, b, c, d, e; cin >> a >> b >> c >> d >> e; ll m = min({a,b,c,d,e}); ll retval = (N+m-1ll)/m + 4ll; cout << retval << endl; // cout << fixed << setprecision(10); return 0; }
0
#include<bits/stdc++.h> using namespace std; #define ll long long #define mtv(kit) cout<<#kit<<" - "<<kit<<"\n"; #define ff first #define ss second #define pb push_back #define rep(i,a,b) for(i=a;i<b;i++) #define pii pair<ll , ll> #define all(x) x.begin(),x.end() #define nl "\n" #define ump unordered_map void doit(){ ll n,i,k,j; cin >> n; vector< ll >v(n); for(i = 0; i < n; i++)cin>>v[i]; vector<pii>answer(61,{0,0}); rep(i,0,n){ rep(j,0,61){ if(v[i] & (1LL << j) )answer[j].ff++; else answer[j].ss++; } } ll ans = 0,mod = 1e9+7; rep(i,0,61){ ll k1 = (answer[i].ff * answer[i].ss)%mod ; ll k2 = (1LL << i)%mod; k1 = (k1*k2)%mod; ans = ((ans % mod) + (k1 % mod)) % mod; } cout << ans; } int main() { #ifndef ONLINE_JUDGE freopen("input1.txt","r",stdin); freopen("output1.txt","w",stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); ll t = 1; // cin >> t; for(ll i = 1; i <= t; i++){ doit(); } }
#include <bits/stdc++.h>//Carefully Crafted by hetp111 using namespace std; #define int long long #define double long double #define all(v) (v).begin(),(v).end() #define vi vector<int> #define vvi vector<vi> #define pii pair<int,int> #define vii vector<pii> #define MOD 1000000007 #define MOD2 998244353 #define MOD3 1000000009 #define PI acos(-1) #define eps (1e-8) #define INF (1e18) #define FASTER ios_base::sync_with_stdio(0);cin.tie(0) template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";} template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;} template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;} template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;} //ifstream cinn("in.in");ofstream coutt("out.out"); int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;} int ceil(const int &a,const int &b){return (a+b-1)/b;} ////Read: //Check corner cases, n==1; // ////Some function: //__builtin_popcountll(), is_sorted(), int n; int v[300005]; int suf[64][300005][2]; signed main(){ FASTER; cin>>n; for(int i=1;i<=n;i++)cin>>v[i]; for(int i=0;i<64;i++){ for(int j=n;j>=1;j--){ suf[i][j][1]=suf[i][j+1][1]+((v[j]>>i)&1); suf[i][j][0]=suf[i][j+1][0]+(1-((v[j]>>i)&1)); } } int ans=0; for(int i=0;i<64;i++){ for(int j=n;j>=1;j--){ int z=suf[i][j+1][0]; int o=suf[i][j+1][1]; if((v[j]>>i)&1){ ans+=(1LL<<i)%MOD*z%MOD; }else{ ans+=(1LL<<i)%MOD*o%MOD; } ans%=MOD; } } cout<<ans; }
1
#include <map> #include <iostream> using namespace std; /** Problem0039 : Roman Figure **/ int main() { char num[110]; int now, old, ans; map<char, int> list; list.insert(map<char, int>::value_type('I', 1)); list.insert(map<char, int>::value_type('V', 5)); list.insert(map<char, int>::value_type('X', 10)); list.insert(map<char, int>::value_type('L', 50)); list.insert(map<char, int>::value_type('C', 100)); list.insert(map<char, int>::value_type('D', 500)); list.insert(map<char, int>::value_type('M', 1000)); while (cin >> num) { ans = 0; old = list[num[0]]; for (int i=1; i<110 && num[i]!='\0'; i++) { now = list[num[i]]; if (old == 0) { old = now; } else if (old<now) { ans += (now-old); old = 0; } else { ans += old; old = now; } } ans += old; cout << ans << endl; } return 0; }
#define _USE_MATH_DEFINES #include <algorithm> #include <cstdio> #include <functional> #include <iostream> #include <cfloat> #include <climits> #include <cstring> #include <cmath> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <time.h> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> i_i; typedef pair<ll, int> ll_i; typedef pair<double, int> d_i; typedef pair<ll, ll> ll_ll; typedef pair<double, double> d_d; struct edge { int u, v; ll w; }; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; int dx[4] = {-1, 0, 1, 0}; int dy[4] = {0, -1, 0, 1}; int main() { for (;;) { int e; cin >> e; if (e == 0) break; int m = INT_MAX; for (int z = 0; z * z * z <= e; z++) { int _e = e - z * z * z; int y = sqrt((double)_e), x = _e - y * y; m = min(m, x + y + z); } cout << m << endl; } }
0
#include<bits/stdc++.h> using namespace std; int main(void){ long long A,B,K; cin>>A>>B>>K; for(int i=0;i<K;i++){ if(i%2==0){ if(A%2!=0){ A-=1; } B+=A/2; A/=2; }else{ if(B%2!=0){ B-=1; } A+=B/2; B/=2; } } cout<<A<<" "<<B<<endl; return 0; }
#include <iostream> #include <string> typedef long long ll; void print() { std::cout << std::endl; } template<class T> void print(T param) { std::cout << param << std::endl; return; } template<class T, class... S> void print(T param1, S... param2) { std::cout << param1 << " "; print(std::forward<S>(param2)...); } int main() { ll A, B, K; std::cin >> A >> B >> K; for (ll i = 0; i < K; i++) { A /= 2; B += A; std::swap(A, B); } if (K % 2 == 1) { std::swap(A, B); } print(A, B); return 0; }
1
#include <bits/stdc++.h> typedef long long ll; typedef long double ld; using namespace std; const int needs[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; bool compare(vector<int>& a, vector<int>& b, int size) { int cnta = 0, cntb = 0; for (int i = 0; i < size; i++) { cnta += a[i]; cntb += b[i]; } if (cnta != cntb) { return cnta > cntb; } else { return a > b; } } int main() { int N, M; cin >> N >> M; vector<int> A(M); for (int i = 0; i < M; i++) { cin >> A[i]; } sort(A.begin(), A.end()); reverse(A.begin(), A.end()); vector<vector<int>> dp(N + 1, vector<int>(M, -1)); for (int i = 0; i < M; i++) { dp[0][i] = 0; } for (int i = 0; i < N; i++) { for (int m = 0; m < M; m++) { if (dp[i][0] == -1) { continue; } vector<int> tmp = dp[i]; tmp[m]++; if (i + needs[A[m]] <= N && compare(tmp, dp[i + needs[A[m]]], M)) { dp[i + needs[A[m]]] = tmp; } } } // for (int n = 0; n <= N; n++) { // cout << "n = " << n << endl; // for (int i = 0; i < M; i++) { // cout << A[i] << " " << dp[n][i] << endl; // } // } string ans = ""; for (int i = 0; i < M; i++) { ans += string(dp[N][i], A[i] + '0'); } sort(ans.begin(), ans.end()); reverse(ans.begin(), ans.end()); cout << ans << endl; }
#include<iostream> #include<cstdio> using namespace std; int n,S,X[202020],st[202020],top; long long P[202020]; void solve(int l,int r) { if(S<=X[l]) return (void)(st[++top]=r); if(S>=X[r]) return (void)(st[++top]=l); if(P[l]<P[r]) return st[++top]=l,P[r]+=P[l],solve(l+1,r); else return st[++top]=r,P[l]+=P[r],solve(l,r-1); } int aabs(int x){ return x<0?-x:x;} int main() { scanf("%d%d",&n,&S); for(int i=1;i<=n;i++) scanf("%d%lld",&X[i],&P[i]); solve(1,n); long long ans=0; while(top) ans+=aabs(S-X[st[top]]),S=X[st[top--]]; printf("%lld\n",ans); return 0; }
0
#include <iostream> #include <algorithm> #include <vector> #include <set> #include <map> using namespace std; #define rep(i, a, b) for(int i = a; i < (b); ++i) typedef long long ll; int main() { ll x,y; cin >> x >> y; ll ans; if (x * y > 0) { if (y >= x) ans = y - x; else ans = x - y + 2; } else if (x * y < 0) { ans = abs(abs(x)-abs(y)) + 1; } else { if (y > x) ans = y - x; else ans = x - y + 1; } cout << ans << endl; return 0; }
#include <stdio.h> int main () { char x[100]; char y[100]; scanf("%s%s\n", &x,&y); printf("%s%s\n", y, x); return 0; }
0
#include <iostream> #include <string> using namespace std; int main(){ int a, b; cin >> a >> b; string s; cin >> s; string ans = "Yes"; for(int i = 0; i < a; i++){ if(!(s[i] >= '0' && s[i] <= '9')) ans = "No"; } if(s[a] != '-') ans = "No"; for(int i = a+1; i < a+b+1; i++){ if(!(s[i] >= '0' && s[i] <= '9')) ans = "No"; } cout << ans << endl; return 0; }
#include<stdio.h> int main() { int A, B; scanf("%d %d", &A, &B); int size = A + B + 1; char str[100]; scanf("%s", str); int i, count = 0; if (str[A] == '-') { for (i = 0; i < size; i++) { if (str[i] >= '0' && str[i] <= '9') { count++; } } if (count == size - 1) { printf("Yes\n"); } else { printf("No\n"); } } else { printf("No\n"); } return 0; }
1
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int,int> pii; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define all(a) (a).begin(),(a).end() #define pb push_back //#define INF (1e9+1) #define INF (1LL<<59) #define int ll signed main(){ int v,e; cin>>v>>e; int d[101][101]; rep(i,101)rep(j,101)d[i][j] = INF; rep(i,101)d[i][i] = 0; rep(i,e){ int s,t,c; cin>>s>>t>>c; d[s][t] = c; } rep(k,v){ rep(i,v){ rep(j,v){ d[i][j]=min(d[i][j],d[i][k]+d[k][j]); } } } rep(i,v){ if(d[i][i]<0){ cout<<"NEGATIVE CYCLE"<<endl; return 0; } } rep(i,v){ rep(j,v){ if(j)cout<<" "; int res=d[i][j]; if(res>=INF/2)cout<<"INF"; else cout<<res; } cout<<endl; } }
#include<bits/stdc++.h> #define MAXN 1000005 #define INF int(16843009) using namespace std; int N,M; struct edge{ int u,v; edge(int u=0, int v=0):u(u), v(v){} }; vector<edge> adjc[MAXN]; vector<int> adj1[MAXN]; void addE(int u, int v){ cerr<<"addE: "<<u<<" "<<v<<endl; adj1[u].push_back(v); adj1[v].push_back(u); } int d[MAXN]; void bfs(){ memset(d, 1, sizeof(d)); d[1] = 0; queue<int> q; q.push(1); int u,v; while(!q.empty()){ u = q.front(); q.pop(); if(u==N) return; for(int k=0;k<adj1[u].size();k++){ v = adj1[u][k]; if(d[u] + 1 < d[v]){ d[v] = d[u] + 1; q.push(v); } } } } int fa[MAXN]; int p[MAXN]; int findR(int x){ if(p[x]==x) return x; else return p[x] = findR(p[x]); } int main(){ scanf("%d%d", &N, &M); int u,v,c; for(int i=1;i<=M;i++){ scanf("%d%d%d", &u, &v, &c); adjc[c].push_back(edge(u,v)); } int top = N; for(int i=1;i<=1e6;i++){ //cout<<i<<endl; if(adjc[i].size()==0) continue; // for(int k=0;k<adjc[i].size();k++){ u = adjc[i][k].u; v = adjc[i][k].v; p[u] = u; p[v] = v; fa[u] = fa[v] = 0; } int ru,rv; for(int k=0;k<adjc[i].size();k++){ u = adjc[i][k].u; v = adjc[i][k].v; ru = findR(u); rv = findR(v); p[ru] = rv; } for(int k=0;k<adjc[i].size();k++){ u = adjc[i][k].u; v = adjc[i][k].v; ru = findR(u); rv = findR(v); // if(fa[ru]) addE(u,fa[ru]); else{ fa[ru] = ++top; addE(u,top); } // if(fa[rv]) addE(v,fa[rv]); else{ fa[rv] = ++top; addE(v,top); } } } //cout<<"pass"<<endl; bfs(); if(d[N]==INF) cout<<"-1"<<endl; else cout<<d[N]/2<<endl; return 0; }
0
#include <bits/stdc++.h> #define err(args...) {} #ifdef DEBUG #include "_debug.cpp" #endif using namespace std; using ll = long long; using ld = long double; template <typename T> using lim = numeric_limits<T>; template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; } const int M = 1'000'000'007; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<ll> x(n), y(m); cin >> x >> y; adjacent_difference(x.begin(), x.end(), x.begin()); adjacent_difference(y.begin(), y.end(), y.begin()); ll ysum = 0; for(int j = 1; j < m; j++) { ysum += y[j] * (m - j) % M * j % M; ysum %= M; } ll xsum = 0; for(int i = 1; i < n; i++) { xsum += x[i] * (n - i) % M * i % M; xsum %= M; } cout << xsum * ysum % M << endl; return 0; }
#include<iostream> #include<vector> #include<algorithm> using namespace std; using ll = long long; const int mod = 1e9 + 7; int main() { int n, m; cin >> n >> m; vector<ll>x(n), y(m); for (auto&& xx : x)cin >> xx;for (auto&& yy : y)cin >> yy; sort(x.begin(), x.end());sort(y.begin(), y.end()); ll a = 0, b = 0; for (int i = 0; i < n; i++)a -= x[i] * (n - 1 - i - i); for (int i = 0; i < m; i++)b -= y[i] * (m - 1 - i - i); cout << (a % mod) * (b % mod) % mod << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; using Graph= vector<vector<int>>; const int TBC= -1; void DFS(const Graph &tree, int parent, int root, vector<int> *parents, vector<int> *pre_timestamp, vector<int> *post_timestamp, vector<int> *depth){ if(parents->at(root)==TBC){ parents->at(root)= parent; pre_timestamp->at(root)= depth->size(); } int depth_root= (!depth->empty()) ? depth->back()+ 1 : 0; depth->emplace_back(depth_root); for(auto child:tree.at(root)){ if(child != parent){ DFS(tree, root, child, parents, pre_timestamp, post_timestamp, depth); depth->emplace_back(depth_root); } } post_timestamp->at(root)= depth->size(); } int main(){ int N,v0_runner,v0_trailer; cin >> N >> v0_runner >> v0_trailer; const int M= N-1; v0_runner--; v0_trailer--; // 1-indexed -> 0-indexed Graph tree(N); int v1,v2; for(int i=0; i<M; i++){ cin >> v1 >> v2; v1--; v2--; // 1-indexed -> 0-indexed tree.at(v1).emplace_back(v2); tree.at(v2).emplace_back(v1); } vector<int> parents(N, TBC); vector<int> pre_timestamp(N, TBC); vector<int> post_timestamp(N, TBC); vector<int> depth; DFS(tree, -1, v0_trailer, &parents, &pre_timestamp, &post_timestamp, &depth); int depth0_runner= depth.at(pre_timestamp.at(v0_runner)); int cnt_up= (depth0_runner- 1)/ 2; int pos_runner= v0_runner; for(int i=0; i<cnt_up; i++){ pos_runner= parents.at(pos_runner); } int depth1_runner= depth.at(pre_timestamp.at(pos_runner)); int left = pre_timestamp.at(pos_runner); int right= post_timestamp.at(pos_runner); int depth_tree= *max_element(depth.begin()+ left, depth.begin()+ right); int ans= (depth0_runner/ 2)+ (depth_tree- depth1_runner); cout << ans << endl; }
#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) << endl #define COUTF(x) cout << setprecision(15) << (x) << endl #define ENDL cout << endl #define DF(x) x.erase(x.begin()) // 先頭文字削除 #define ALL(x) x.begin(), x.end() #define SORT(x) sort(ALL(x)) #define REVERSE(x) reverse(ALL(x)) #define ANS cout << ans << endl #define RETURN(x) \ cout << x << endl; \ return 0 clock_t CLOCK; #define START_TIMER CLOCK = clock() #define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << endl #define init() \ cin.tie(0); \ ios::sync_with_stdio(false) #define debug(x) cerr << "[debug] " << #x << ": " << x << endl; #define debugV(v) \ cerr << "[debugV] " << #v << ":"; \ rep(i, v.size()) cerr << " " << v[i]; \ cerr << endl; 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, u, v; cin >> N >> u >> v; u--; v--; vvll to(N); rep(i, N - 1) { ll a, b; cin >> a >> b; a--; b--; to[a].pb(b); to[b].pb(a); } queue<P> q1; q1.push({u, 1}); vll d1(N); while (!q1.empty()) { ll index = q1.front().first; ll distance = q1.front().second; q1.pop(); if (d1[index] != 0) continue; d1[index] = distance; rep(i, to[index].size()) { q1.push({to[index][i], distance + 1}); } } debugV(d1); queue<P> q2; q2.push({v, 1}); vll d2(N); while (!q2.empty()) { ll index = q2.front().first; ll distance = q2.front().second; q2.pop(); if (d2[index] != 0) continue; d2[index] = distance; rep(i, to[index].size()) { q2.push({to[index][i], distance + 1}); } } debugV(d2); ll ans = 0; rep(i, N) { if (d1[i] < d2[i]) ans = max(ans, d2[i]); } ans--; ans--; COUT(ans); return 0; }
1
#include <bits/stdc++.h> using namespace std; #define for_(i,a,b) for(int i=(a);i<(b);++i) int main() { string L = ""; for_(i,0,26) L += char('a' + i); for_(i,0,26) L += char('A' + i); int n; while (cin >> n, n) { vector< int > k(n); for_(i,0,n) cin >> k[i]; string s; cin >> s; int m = s.size(); for_(i,0,m) { int pos = L.find(s[i]); s[i] = L[(pos - k[i%n] + 52) % 52]; } cout << s << endl; } }
#include <bits/stdc++.h> #define ll long long #define MODV 1000000007 #define INF INT_MAX // 2147483647 #define INFLL LLONG_MAX // 9223372036854775807 #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 per(i, n) for(ll i=((ll)(n))-1; i>=0; i--) #define perf(i, n) for(ll i=((ll)(n)); i>0; 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; int main(){ Init(); ll n, t, sum = 0; cin >> n >> t; ll pt; cin >> pt; rep(i, n-1){ ll np; cin >> np; if(np-pt >= t) sum += t; else sum += np-pt; pt = np; } sum += t; cout << sum << endl; }
0
#include<bits/stdc++.h> using namespace std; #define int long long const int N=2000+5,base=2001*3; int f[N*3][N*6],mod; void add(int &x,int y){ x=(x+y)%mod; } signed main(){ int n; cin>>n>>mod; n*=3; f[0][base]=1; for(int i=0;i<n;++i) for(int j=-i;j<=i;++j) if(f[i][j+base]){ add(f[i+1][j+1+base],f[i][j+base]); add(f[i+2][j-1+base],1ll*f[i][j+base]*(i+1)%mod); add(f[i+3][j+base],1ll*f[i][j+base]*(i+1)%mod*(i+2)%mod); } int ans=0; for(int j=0;j<=n;++j) add(ans,f[n][j+base]); cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; vector<int> pref(n, 0), suff(n, 0); for (int i = 1; i < n; i++) { pref[i] = pref[i-1] + (s[i-1] == 'W'); } for (int i = n-2; i >= 0; i--) { suff[i] = suff[i+1] + (s[i+1] == 'E'); } int ans = 1e8; for (int i = 0; i < n; i++) { ans = min(ans, pref[i] + suff[i]); } cout << ans << endl; }
0
/*!enjoy karo yaar!*/ //CF,CC,AtC,SPOJ: hp1999 //HE: hemant269 //HR: hemant2132 #include<bits/stdc++.h> using namespace std; /*-----<Defines>-----*/ #define int long long int #define fast() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define all(x) begin(x),end(x) #define rz(x) resize(x) #define asn(x,y) assign(x,y) #define mem(a,b) memset(a,b,sizeof(a)) #define sz(x) ((int)size(x)) #define eb emplace_back #define pb push_back #define pf push_front #define pob pop_back #define pof pop_front #define ins insert #define vi vector<int> #define pii pair<int,int> #define mii map<int,int> #define F first #define S second #define remax(a,b) a=max(a,b) #define remin(a,b) a=min(a,b) #define bitcount(x) __builtin_popcountll(x) #define iceil(n,x) (((n)-1)/(x)+1) #define flush fflush(stdout) using ull=unsigned long long; using ll=long long; using ld=long double; /*-----</Defines>-----*/ /*-----<Debugging Stuff>-----*/ string to_string(char s) { string res="'''";res[1]=s;return res; } 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.F)+", "+to_string(p.S)+")"; } template<typename A> string to_string(A v) { bool first=1; string res="{"; for(const auto &x:v) { if(!first) res+=", "; first=0; res+=to_string(x); } res+="}"; return res; } void debug() { cout<<"\n"; } template<typename Head, typename... Tail> void debug(Head H, Tail... T) { cout<<" "<<to_string(H); debug(T...); } #define show(...) cout << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__) /*-----</Debugging Stuff>-----*/ /*-----<Mod Operations>-----*/ const int M=1e9+7; inline int add(int a,int b,int p=M){ a=a+b; if(a>=p) a-=p; return a; } inline int sub(int a,int b,int p=M){ a=a-b; if(a<0) a+=p; return a; } inline int mul(int a,int b,int p=M){ a=(a*1ll*b)%p; return a; } /*-----</Mod Operations>-----*/ /*-----<Constants>-----*/ const ld pi=acos(-1),eps=1e-9; const ll inf=1e18; const int N=1; /*-----</Constants>-----*/ void solve() { int n,m; cin>>n>>m; if(n%2) { for(int cur=1;m;--m,++cur) { cout<<cur<<" "<<n-cur+1<<"\n"; } return; } int mx=(n-1)/2; int split; if(mx%2) split=mx-1; else split=mx; int l=1,r=split+1; for(int i=r-l;i>=2;i-=2) { if(i<=m) cout<<l<<" "<<r<<"\n"; ++l,--r; } l=split+2; r=l+split+(mx%2?1:-1); for(int i=r-l;i>=1;i-=2) { if(i<=m) cout<<l<<" "<<r<<"\n"; ++l,--r; } } int32_t main() { fast(); int t=1; //cin>>t; for(int z=1;z<=t;++z) { solve(); //cout<<"\n"; } return 0; }
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; typedef long long ll; int main() { int N, M; cin >> N >> M; vector<int> num(N, -1); for (int i=0; i<M; i++) { int si, ci; cin >> si >> ci; si--; if ((num[si] != -1) && (num[si] != ci)){ cout << -1; return 0; } num[si] = ci; } if (N == 1) { if (num[0] == -1) { cout << 0; return 0; } else { cout << num[0]; return 0; } } else { for (int j=0; j<N; j++){ if (j == 0 && num[j] == 0) { cout << -1; return 0; } if (j == 0 && (num[j] == -1)){ num[j] = 1; } if (num[j] == -1) { num[j] = 0; } } } // // bool first_val = true; // for (int j=0; j<N; j++) { // if ((j == 0) && (num[j] == 0) && (N != 1)){ // cout << -1; // return 0; // } else if ((j == 0) && (num[j]==-1)) { // num[j] = 1; // } // // if (num[j] != -1) first_val = false; // // if ((j==0) && (num[j] == -1)) num[j] = 1; // if (num[j] == -1){ // num[j] = 0; // } // } int ans = 0; for (int k=0; k<N;k++) { ans = ans * 10 + num[k]; } cout << ans << endl; }
0
#include<iostream> #include<queue> #include<cmath> #include<algorithm> using namespace std; int n,m,ans=0x3f3f3f3f; int a[100000+5]; int main(){ cin>>n>>m; for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=1;i<=n-m+1;i++){ int j=m+i-1; ans=min(ans,min(abs(a[i])+abs(a[j]-a[i]),abs(a[j])+abs(a[j]-a[i]))); } if(ans==0x3f3f3f3f) cout<<0<<endl; cout<<ans<<endl; }
#include <iostream> #include <stdio.h> #include <string> #include <algorithm> #include <vector> #include <math.h> #include <numeric> #include <queue> #include <numeric> #include <iomanip> #include <sstream> #include <cmath> #include <map> #include <functional> #include <limits> #include <set> #include <stack> #include <cctype> #define rep(i,a,b) for((i)=a;i<(int)(b);i++) #define AAA (1000000007) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pairII; ll gcd(ll a, ll b) { if (b == 0)return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll powD(ll a, ll b) { ll ans = 1; a %= AAA; for (int i = 0; i < b; i++) { ans *= a; ans %= AAA; } return ans; } int main() { int i, j, k; int N, M, K; vector<int> X; cin >> N >> K; rep(i, 0, N) { int x; cin >> x; X.push_back(x); } ll ans = abs(X[0])*2 + abs(X[N - 1])*2; rep(i, 0, N-K+1) { ll a = min(abs(X[i]), abs(X[i + K-1])); ll b = max(abs(X[i]), abs(X[i + K-1])); if (X[i] < 0 && X[i + K - 1]>0) { ans = min(ans, a * 2 + b); } else { ans = min(ans,b); } } cout << ans; return 0; }
1
#include <stdio.h> int main(){ int n,now=-1,temp,a[100000]; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",&a[i]); } for(int i=0;i<n;i++){ if(a[i]<=a[n-1]){ now++; temp=a[i]; a[i]=a[now]; a[now]=temp; } } for(int i=0;i<now;i++)printf("%d ",a[i]); printf("[%d]",a[now]); for(int i=now+1;i<n;i++)printf(" %d",a[i]); printf("\n"); }
#include<iostream> #include<map> #include<string> #include<vector> using namespace std; int inf = 10000000; int n; vector<int> a; int partition(int p, int r){ int x = a[r-1]; int i = p-1; for(int j=p; j<r; j++){ if( a[j] <= x ){ // i = i + 1; swap(a[++i], a[j]); } } // swap(a[i+1], a[r]); return i; } int main(){ cin >> n; a.resize(n); for(int i=0; i<n; i++) cin >> a[i]; int p = partition(0, n); for(int i=0; i<n; i++){ if( i == p ) cout << "[" << a[i] << "]"; else cout << a[i]; if( i == n-1 ) cout << endl; else cout << " "; } return 0; }
1
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using P = pair<int, int>; typedef long long ll; int main() { ll x; cin >> x; ll ans = (x / 11) * 2; if(ans > 0){ x %= 11; } if(x > 6){ ans += 2; }else if(x > 0){ ans++; } cout << ans << endl; }
#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() { string s; cin >> s; vector<bool> flg(26, false); int n = s.size(); rep(i, n) flg[s[i] - 'a'] = true; rep(i, 26) { if (!flg[i]) { cout << (char)(i + 'a') << endl; return 0; } } cout << "None" << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define int long long int #define pii pair<int,int> #define vpii vector<pii> #define vi vector<int> #define fi first #define se second #define psb push_back #define ppb pop_back #define fio ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL) #define all(x) x.begin(),x.end() #define endl "\n" int ar[300]; int32_t main() { int t; cin>>t; while(t--) { int n; cin>>n; for(int i=0;i<n;i++) cin>>ar[i]; string s; cin>>s; int ans=0; set<int,greater<int>> st; for(int i=n-1;i>=0;i--) { for(int e:st) ar[i]=min(ar[i],ar[i]^e); if(ar[i]==0) continue; if(s[i]=='0') st.insert(ar[i]); else { ans=1; break; } } cout<<ans<<endl; } }
#include<bits/stdc++.h> using namespace std; #define int long long typedef vector<int>vint; typedef pair<int,int>pint; typedef vector<pint>vpint; #define rep(i,n) for(int i=0;i<(n);i++) #define reps(i,f,n) for(int i=(f);i<(n);i++) #define all(v) (v).begin(),(v).end() #define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++) #define pb push_back #define fi first #define se second template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;} template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;} namespace SCC{ void visit(const vector<vector<int>>&G,vector<int>&vs,vector<int>&used,int v){ used[v]=true; for(auto u:G[v]){ if(!used[u])visit(G,vs,used,u); } vs.push_back(v); } void visit2(const vector<vector<int>>&T,vector<int>&used,vector<int>&comp,int k,int v){ comp[v]=k; used[v]=true; for(auto u:T[v]){ if(!used[u])visit2(T,used,comp,k,u); } } void decompose(const vector<vector<int>>&G,vector<vector<int>>&H,vector<int>&comp){ vector<vector<int>>T(G.size()); for(int i=0;i<G.size();i++){ for(auto v:G[i]){ T[v].push_back(i); } } comp.resize(G.size()); vector<int>vs(G.size()); vector<int>used(G.size()); for(int i=0;i<G.size();i++){ if(!used[i])visit(G,vs,used,i); } reverse(vs.begin(),vs.end()); fill(used.begin(),used.end(),0); int K=0; for(auto v:vs){ if(!used[v]){ visit2(T,used,comp,K++,v); } } H.resize(K); for(int i=0;i<G.size();i++){ for(auto v:G[i]){ H[comp[i]].push_back(comp[v]); } } for(int i=0;i<K;i++){ sort(H[i].begin(),H[i].end()); H[i].erase(unique(H[i].begin(),H[i].end()),H[i].end()); } } } signed main(){ int N,M; scanf("%lld%lld",&N,&M); vector<vector<int>>G(N); rep(i,M){ int a,b; scanf("%lld%lld",&a,&b); G[a].push_back(b); } vector<vector<int>>H; vector<int>comp; SCC::decompose(G,H,comp); int Q; scanf("%lld",&Q); while(Q--){ int a,b; scanf("%lld%lld",&a,&b); printf("%lld\n",(int)(comp[a]==comp[b])); } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { string s, ans; int w, i = 0; cin >> s >> w; while(i < (int)s.size()) { ans += s[i]; i += w; } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; int main() { int A,B,ans=0; cin >> A >> B; if(A>B) ans += 2*A -1; else if(A<B) ans += 2*B -1; else if(A==B) ans += 2*A; cout << ans << endl; }
0
#include<bits/stdc++.h> #define rep(i,n,m) for(int i = (n); i <(m); i++) #define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--) #define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;} #define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;} using namespace std; using ll = long long; // Binary Indexed Tree (Fenwick Tree) template<typename T> struct BIT { int n; vector<T> d; BIT(int n=0):n(n),d(n+1) {} void add(int i, T x=1) { for (i++; i <= n; i += i&-i) { d[i] += x; } } T sum(int i) { T x = 0; for (i++; i; i -= i&-i) { x += d[i]; } return x; } T sum(int l, int r) { return sum(r-1) - sum(l-1); } }; int main() { int N, Q; cin >> N >> Q; // read input as range vector<pair<int, int>> clr_rng; { unordered_map<int, int> prepos; rep(i, 1, N+1) { int c; cin >> c; clr_rng.emplace_back(prepos[c], i); prepos[c] = i; } } vector<tuple<int, int, int>> qry; rep(i, 0, Q) { int l, r; cin >> l >> r; qry.emplace_back(l, r, i); } // sort by start pos sort(clr_rng.rbegin(), clr_rng.rend()); sort(qry.rbegin(), qry.rend()); // countint with bit BIT<ll> bit(N+1); vector<int> ans(Q); int pos_c = 0; int pos_q = 0; rrep(pos, N+1, 1) { // add range while (pos_c < (int) clr_rng.size()) { int frm, to; tie(frm, to) = clr_rng[pos_c]; if (frm < pos) break; // printf("from: %d, to: %d\n", frm, to); bit.add(to, 1); ++pos_c; } // process query while (pos_q < (int) qry.size()) { int frm, to, i; tie(frm, to, i) = qry[pos_q]; if (frm < pos) break; int num = to - frm + 1; num -= bit.sum(to); // printf("from: %d, to: %d, i: %d, bit: %lld\n", frm, to, i, bit.sum(to)); ans[i] = num; ++pos_q; } } // output answer rep(i, 0, Q) printf("%d\n", ans[i]); return 0; }
#include <iostream> #include <string> #include <algorithm> #include <functional> #include <vector> #include <stack> #include <queue> #include <deque> #include <set> #include <map> #include <cstdio> #include <cmath> #include <tuple> #include <iomanip> #include <numeric> #include <unordered_map> #include <sstream> #include<limits.h> #include<float.h> #include<list> #include <array> #include <complex> #include<stdio.h> #include<string.h> #include <bitset> // #include<assert.h> #include<random> using namespace std; #define int long long #define I32_MAX 2147483647 #define I64_MAX 9223372036854775807LL #define I64_MAX2 1223372036854775807LL #define INF I64_MAX2 #define MOD 1000000007 // #define MOD 998244353 #define MEM_SIZE 100010 #define DEBUG_OUT true #define ALL(x) (x).begin(), (x).end() template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";} template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;} template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } } template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);} template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}} template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } //https://www.youtube.com/watch?v=RDaGj_ztNz4&feature=youtu.be //-----CODE------// int dfs(int v,int c,vector<vector<int> > & GRAPH,vector<int> & color) { color[v] = c; // DEBUG(color); for (auto &&u : GRAPH[v]) { if(color[u] == c) { return false; } if(color[u] ==0 && !dfs(u,-1*c,GRAPH,color)) { return false; } } return true; } void solve(void) { int n,m; cin>>n>>m; vector<vector<int> > GRAPH (n); for (int i = 0; i < m; i++) { int A,B; cin>>A>>B; A--;B--; GRAPH[A].push_back(B); GRAPH[B].push_back(A); } int b = 0,w = 0; vector<int> color(n,0); if(dfs(0,1,GRAPH,color)) { for (int i = 0; i < n; i++) { if(color[i] == 1) { b++; } else if(color[i] == -1) { w++; } } cout<<b*w - m <<endl; } else { cout<<n*(n-1)/2 - m<<endl; } return; } int32_t main(int32_t argc, const char *argv[]) { std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout << std::fixed; std::cout << std::setprecision(11); solve(); return 0; }
0
#include<bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= m; ++i) if (2 * i < m + 2) printf("%d %d\n", i, m + 2 - i); for (int i = 1; i <= m; ++i) if (2 * i < m + 1) printf("%d %d\n", m + 1 + i, 2 * m + 2 - i); return 0; }
#include <bits/stdc++.h> #define INF 1e9 using namespace std; #define REPR(i,n) for(int i=(n); i >= 0; --i) #define FOR(i, m, n) for(int i = (m); i < (n); ++i) #define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define ALL(a) (a).begin(),(a).end() #define endl "\n" template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; } template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } typedef long long ll; void solve() { string s; int w; cin >> s; cin >> w; REP(i,s.size()) if(i%w == 0) cout << s[i]; cout << endl; } int main() { solve(); return 0; }
0
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define rep(i,n) for(int i=0;i<(n);i++) #define init(a,i) for(int k=0;k<(i);k++)(a)[k]=0 #define in(a,i) for(int k=0;k<(i);k++)cin>>(a)[k] int main(){ ll n; cin>>n; stack<char> st; while(n!=0){ n--; st.push('a'+n%26); n/=26; } while(!st.empty()){ cout<<st.top(); st.pop(); } return 0; }
#include <iostream> #include <string> #include <cstring> #include <cstdlib> using namespace std; string convert(string str) { int idx = 0; for (;;) { idx = str.find("Hoshino", idx); if (idx == string::npos) break; str.replace(idx, 7, "Hoshina"); idx += 7; } return str; } int main() { int n; string str; getline(cin, str); n = atoi(str.c_str()); for (int i = 0; i < n; i++) { getline(cin, str); cout << convert(str) << endl; } return 0; }
0
#include <stdio.h> int main(){ char c; char s[21]={'\0'}; int i = 0,j; c = getchar(); while(c != '\n'){ for(j=i;j>=0;j--){ s[j+1] = s[j]; } i++; s[0] = c; c = getchar(); } printf("%s\n",s); }
#include <bits/stdc++.h> #define REP(i, n) for(int i = 0; i < n; i++) #define REPR(i, n) for(int i = n; i >= 0; i--) #define FOR(i, m, n) for(int i = m; i < n; i++) #define INF 2e9 #define MOD 1000000007 #define ALL(v) v.begin(), v.end() using namespace std; typedef long long ll; using P = pair<int,int>; vector<ll> vec; vector<ll> vec2; void init(){ ll x = 1; ll x2 = 1; while(x<10000000000){ vec.push_back(x); x2*=4; x+=x2; } ll y = 0; ll y2 = 2; while(y>-10000000000){ vec2.push_back(y); y-=y2; y2*=4; } } vector<ll> ans(33,0); void solve(ll N){ if(N==1){ ans.at(0)=1; }else if(N==0){ ans.at(0)=0; }else if(N>1){ REP(i,vec.size()){ if(N<=vec.at(i)){ ans.at(i*2)=1; solve(N-pow(2,i*2)); break; } } }else if(N<0){ REP(i,vec2.size()){ if(vec2.at(i)<=N){ ans.at(i*2-1)=1; solve(N+pow(2,i*2-1)); break; } } } } int main() { ll N; cin >> N; init(); solve(N); int flag = 0; REPR(i,32){ if(ans.at(i)==1&&flag==0){ flag=1; } if(flag==1){ cout << ans.at(i); } } if(flag==0){ cout << 0; } cout << endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int k,x; cin >> k >> x; for(int i=-k+1;i<k;i++){ cout << x+i << " "; } }
#include <bits/stdc++.h> //登録しよう!→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ using namespace std; using ll = long long; ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;} //↑nの約数を求める vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;} //↑エラトステネスの篩で素数を求める #define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算 #define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ #define size_t ll //size_tは自動でllに変換される #define pb(x) push_back(x) #define gre greater //sortを降順にする #define pri_queue priority_queue //優先度付きキュー #define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示 void solve(std::string S, long long w){ string ans =""; int i = 0; while(i < S.length()){ ans += S[i]; i += w; } cout << ans << endl; } // Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) int main(){ std::string S; std::cin >> S; long long w; scanf("%lld",&w); solve(S, w); }
0
#include <algorithm> #include <climits> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <vector> #define int long long int constexpr int INF = std::numeric_limits<int>::max(); constexpr int NINF = std::numeric_limits<int>::min(); using namespace std; void solve() { int M; cin >> M; int ans = 0; int sum = 0; while (M--) { int c, d; cin >> d >> c; ans += c; sum += d*c; } ans -= 1; ans += (sum - 1)/9; cout << ans << endl; } signed main() { cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll M; deque<ll> d; deque<ll> c; deque<ll> e; int main(){ cin >> M; for(int i=0;i<M;i++){ ll a,b; cin >> a >> b; d.push_back(a); c.push_back(b); } ll count = 0; while(d.size() > 0){ if(c[0] == 1){ e.push_back(d[0]); c.pop_front(); d.pop_front(); continue; } ll dd = d[0]; ll cc = c[0]; c.pop_front(); d.pop_front(); if(dd < 5){ if(cc % 2 == 1){ c.push_front(1); d.push_front(dd); } c.push_front(cc/2); d.push_front(dd*2); count += cc/2; continue; } if(cc % 2 == 1){ c.push_front(1); d.push_front(dd); } dd = (dd*2)/10 + (dd*2)%10; c.push_front(cc/2); d.push_front(dd); count += cc/2 * 2; } while(e.size() > 1){ ll a = e[0]; ll b = e[1]; e.pop_front(); e.pop_front(); if(a+b < 10){ count++; e.push_front(a+b); }else{ count += 2; e.push_front((a+b)/10 + (a+b)%10); } } cout << count << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; #define NDEBUG #ifdef DEBUG #include "../cout11.h" #undef NDEBUG #endif #include <cassert> typedef long long ll; typedef long double Double; typedef unsigned long long ull; typedef pair<int,int> ii; typedef pair<ll,ll> llll; typedef pair<double,double> dd; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<ii> vii; typedef vector<vector<ii>> vvii; typedef vector<ll> vll; typedef vector<string> vs; typedef vector<double> vd; typedef vector<long double> vD; #define sz(a) int((a).size()) #define pb push_back #define FOR(var,from,to) for(int var=(from);var<=(to);++var) #define rep(var,n) for(int var=0;var<(n);++var) #define rep1(var,n) for(int var=1;var<=(n);++var) #define repC2(vari,varj,n) for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj) #define ALL(c) (c).begin(),(c).end() #define RALL(c) (c).rbegin(),(c).rend() #define tr(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i) #define found(s,e) ((s).find(e)!=(s).end()) #define mset(arr,val) memset(arr,val,sizeof(arr)) #define mid(x,y) ((x)+((y)-(x))/2) #define IN(x,a,b) ((a)<=(x)&&(x)<=(b)) #define cons make_pair long long max_box_area_in_histogram(vector<int>& a) { int N = a.size(); vector<int> L(N); stack<int> st; for (int i=0; i<N; ++i) { while (!st.empty() && a[st.top()] >= a[i]) { st.pop(); } L[i] = (st.empty() ? -1 : st.top())+1; st.push(i); } while (!st.empty()) st.pop(); vector<int> R(N); for (int i=N-1; i>=0; --i) { while (!st.empty() && a[st.top()] >= a[i]) { st.pop(); } R[i] = (st.empty() ? N : st.top())-1; st.push(i); } long long smax = 0; for (int i=0; i<N; ++i) { int h = a[i], w = R[i] - L[i] + 1; // ll s = (long long)h * w; ll s = (long long)(h + 1)*(w + 1); smax = max(smax, s); } return smax; } ll solve(int H, int W, vector<string>& s) { vvi a(H-1, vi(W-1, 0)); rep(r, H-1) { rep(c, W-1) { a[r][c] = (s[r][c] == '#') ^ (s[r][c+1] == '#') ^ (s[r+1][c] == '#') ^ (s[r+1][c+1] == '#'); } } ll best = max(W, H); vi histo(W-1, 0); rep(r, H-1){ rep(c, W-1) { if (a[r][c]) histo[c] = 0; else histo[c]++; } best = max(best, max_box_area_in_histogram(histo)); } return best; } int main() { int H, W; cin >> H >> W; vector<string> s(H); rep(i, H) cin >> s[i]; cout << solve(H,W,s) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define stoi stoll using ll=long long; using vi=vector<int>; using pii=pair<int,int>; #define ALL(c) begin(c),end(c) #define RALL(c) rbegin(c),rend(c) #define ITR(i,b,e) for(auto i=(b);i!=(e);++i) #define FORE(x,c) for(auto &x:c) #define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i) #define REP(i,n) REPF(i,0,n) #define REPR(i,n) for(int i=(int)(n);i>=0;--i) #define SZ(c) ((int)c.size()) #define CONTAIN(c,x) (c.find(x)!=end(c)) #define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w)) #define dump(...) const signed INF_=1001001001; const ll INF=1001001001001001001LL; const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0}; template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;} template<class T> istream& operator>>(istream &is,vector<T> &v) { ITR(i,begin(v),end(v)) is>>*i;return is;} template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) { is>>p.first>>p.second;return is;} template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;} template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;} template<class T> using heap=priority_queue<T,vector<T>,greater<T>>; struct{template<class T> operator T(){T x;cin>>x;return x;}} IN; struct before_main_function { before_main_function() { cin.tie(0);ios::sync_with_stdio(false); cout<<setprecision(15)<<fixed; #define endl "\n" } } before_main_function; //------------------8<------------------------------------8<-------------------- int H,W; vector<vector<int>> b; int calc(int y) { int ret=0; stack<pair<int,int>> st; REP(j,W) { if(st.empty() || st.top().first<b[y][j]) { st.push({b[y][j],j}); } else if(st.top().first>b[y][j]) { int idx=0; while(!st.empty() && st.top().first>b[y][j]) { auto tp=st.top(); idx=tp.second; st.pop(); chmax(ret,(j-tp.second+1)*tp.first); } st.push({b[y][j],idx}); } } return ret; } signed main() { cin>>H>>W; vector<string> S(H); cin>>S; b=vector<vector<int>>(H,vector<int>(W,0)); REP(j,W-1) { b[0][j]=1; REPF(i,1,H) { if((S[i][j]==S[i][j+1])==(S[i-1][j]==S[i-1][j+1])) { b[i][j]=b[i-1][j]+1; } else { b[i][j]=1; } } } int ans=max(H,W); REP(i,H) { chmax(ans,calc(i)); } cout<<ans<<endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; template< typename T > size_t longest_increasing_subsequence(const vector< T > &a, bool strict) { vector< T > lis; for(auto &p : a) { typename vector< T >::iterator it; if(strict) it = lower_bound(begin(lis), end(lis), p); else it = upper_bound(begin(lis), end(lis), p); if(end(lis) == it) lis.emplace_back(p); else *it = p; } return lis.size(); } int main(){ int N; cin>>N; vector<int> A(N); for(int i=N-1;i>=0;i--){ cin>>A[i]; } cout<<longest_increasing_subsequence(A,false)<<endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define FAST ios_base::sync_with_stdio(false); cin.tie(0); #define LLINF ((long long) 1e18)//1234567890987654321 #define INF 1234567890ll #define pb push_back #define ins insert #define f first #define s second #define db 0 #define EPS (1e-7) //0.0000001 the value #define PI (acos(-1)) #define MAXN (300006) #define MAXK 26 #define MAXX 15000006 #define ll long long int #define ld long double mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng) #define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ++ii) #define space " " #define cbr cerr << "hi\n" #define mmst(x, v) memset((x), v, sizeof ((x))) #define siz(x) ((ll)x.size()) #define ph push #define btinpct(x) __builtin_popcountll(x) #define p2(x) (1LL<<(x)) #define all(x) (x).begin(), (x).end() #define lbd(x, y) lower_bound(all(x), y) #define ubd(x, y) upper_bound(all(x), y) typedef pair <ll, ll> pi; typedef pair <ll, pi> spi; typedef pair <pi, pi> dpi; inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss ll n, A[MAXN], dp[302*302], dp2[302*302]; const ll MOD=998244353; ll qexp(ll x, ll e) { if(e==0) return 1; ll half = qexp(x,e/2); half *= half; half %= MOD; if(e%2) half *= x; half %= MOD; return half; } int main() { cin>>n; FOR(i,0,n) cin>>A[i]; ll sum=accumulate(A,A+n,0); dp[0]=1;dp2[0]=1; for(ll i=0;i<n;i++) { for(ll j=sum;j>=0;j--) { // dp[j] = dp[j] + (dp[j]*2)%MOD; dp[j] %= MOD; dp[j] *= 2; dp[j] %= MOD; if(j>=A[i])dp[j] += dp[j-A[i]]; dp[j] %= MOD; if(j>=A[i])dp2[j] += dp2[j-A[i]]; dp2[j] %= MOD; } } ll ans = qexp(3,n-1); for(ll i=(sum+1)/2;i<=sum;++i) { ans -= (dp[i]); ans += MOD; ans %= MOD; } if(sum%2==0) { ans += dp2[sum/2]; ans %= MOD; } cout<<(ans*3LL)%MOD<<'\n'; }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define mp make_pair #define pb push_back #define rep(i,n) for(int i=0;i<n;i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) bool check(string s){ if(s == "Vacant") return true; else return false; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; cout << 0 << endl; vector<string> s(n); cin >> s[0]; if(check(s[0])) return 0; cout << n-1 << endl; cin >> s[n-1]; if(check(s[n-1])) return 0; int lb =0; int ub = n-1; while(ub - lb>1){ int mid = (ub+lb)/2; cout << mid << endl; cin >> s[mid]; if(check(s[mid])) return 0; if((mid - lb)%2==0){ if(s[mid]==s[lb]){ lb = mid; } else{ ub = mid; } } else{ if(s[mid]!=s[lb]){ lb = mid; } else{ ub = mid; } } } cout << ub << endl; cin >> s[ub]; if(check(s[ub])) return 0; cout << lb << endl; cin >> s[lb]; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define mp make_pair #define PI pair<ll,ll> #define poly vector<ll> #define mem(a) memset((a),0,sizeof(a)) #define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++) #define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--) #define pb push_back #define fi first #define se second #define SZ(x) ((int)(x.size())) inline char gc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++; } #define gc getchar inline ll read(){ ll x = 0; char ch = gc(); bool positive = 1; for (; !isdigit(ch); ch = gc()) if (ch == '-') positive = 0; for (; isdigit(ch); ch = gc()) x = x * 10 + ch - '0'; return positive ? x : -x; } inline void write(ll a){ if(a<0){ a=-a; putchar('-'); } if(a>=10)write(a/10); putchar('0'+a%10); } inline void writeln(ll a){write(a); puts("");} inline void wri(ll a){write(a); putchar(' ');} ll rnd(){ ull ans=0; For(i,0,4)ans=ans<<15^rand(); return ans%((ull)1<<63); } const int N=10005; int a[N],b[N]; void GG(){ puts("No"); exit(0); } char ask(int t){ cout<<t<<endl; string s; cin>>s; if(s[0]=='V')exit(0); return s[0]; } void solve(int l,int r,char L){ int mid=(l+r)>>1; char t=ask(mid); if((t==L)^(l%2)^(mid%2))solve(mid,r,t); else solve(l,mid,L); } int main(){ #ifdef Brollan //freopen("1.in","r",stdin); #endif int n=read(); ask(n-1); solve(0,n-1,ask(0)); }
1
#include<iostream> #include<algorithm> using namespace std ; int W , H , sx , sy ; int ans ; char p ; int dx[] = {-1,0,1,0} ; int dy[] = {0,1,0,-1} ; int table[23][23] ; void DFS( int x , int y , int cnt ){ if( cnt+1 >= ans ) return ; for( int i=0 ; i<4 ; i++ ){ int nx = x + dx[i] , ny = y + dy[i] ; if( table[ny][nx] == 1 ){ continue ; } else { while( table[ny][nx] != 4 ){ if( table[ny][nx] == 1 ){ table[ny][nx] = 0 ; DFS( nx-dx[i] , ny-dy[i] , cnt+1 ) ; table[ny][nx] = 1 ; break ; } else if( table[ny][nx] == 3 ){ ans = min( ans , cnt+1 ) ; return ; } nx += dx[i] ; ny += dy[i] ; }} } return ; } int main(){ while( cin >> W >> H , W ){ for( int i=0 ; i<=H+1 ; i++ ){ for( int j=0 ; j<=W+1 ; j++ ){ if( i==0 || j==0 || i==H+1 || j==W+1 ) table[i][j] = 4 ; else{ cin >> table[i][j] ; if( table[i][j] == 2 ){ sx = j ; sy = i ; } } } } ans = 11 ; DFS( sx , sy , 0 ) ; if( ans == 11 ) ans = -1 ; cout << ans << endl ; } return 0; }
#include <iostream> #include <stdio.h> #include <string> #include <algorithm> #include <vector> using namespace std; int a[5]; bool isStraight(){ vector<int> n; for(int i=0 ; i<5 ; i++){ n.push_back(a[i]); } sort( n.begin(), n.end() ); if( n[0]+1 == n[1] && n[1]+1 == n[2] && n[2]+1 == n[3] && n[3]+1 == n[4]){ return true; } if( n[0]==1 && n[1]==10 && n[2]==11 && n[3]==12 && n[4]==13){ return true; } return false; } string checkCard(){ int n, count, c[5]; int c2=0, c3=0, c4=0; for(int j=0 ; j<5 ; j++){ count = 0; n = a[j]; for(int i=0 ; i<5 ; i++){ if(a[i]==n)count++; } c[j] = count; } for(int i=0 ; i<5 ; i++){ if(c[i]==2)c2++; if(c[i]==3)c3++; if(c[i]==4)c4++; } if(c4==4) return "four card"; else if(c3==3 && c2==2) return "full house"; else if( isStraight() ) return "straight"; else if(c3==3) return "three card"; else if(c2==4) return "two pair"; else if(c2==2) return "one pair"; else return "null"; } int main(){ string str; char s[80]; while( scanf("%d,%d,%d,%d,%d", &a[0], &a[1], &a[2], &a[3], &a[4] ) != EOF ){ str = checkCard(); printf("%s\n",str.c_str()); } return 0; }
0
#include <algorithm> #include <iostream> #include <math.h> using namespace std; int main(){ int d; while(cin){ cin >> d; if(!cin) break; int itg=0; for(int i=1;i*d<600;i++) itg+=pow(i*d,2)*d; cout << itg << endl; } }
#include <iostream> using namespace std; int main() { int d; while (cin >> d) { cout << 72000000 - 180000 * d + 100 * d * d << endl; } return 0; }
1
#include <bits/stdc++.h> #define ADD(a, b) a = (a + ll(b)) % mod #define MUL(a, b) a = (a * ll(b)) % mod #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define rep(i, a, b) for(int i = int(a); i < int(b); i++) #define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--) #define all(a) (a).begin(), (a).end() #define sz(v) (int)(v).size() #define pb push_back #define sec second #define fst first #define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<int, pi> ppi; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vl> mat; typedef complex<double> comp; void Debug() {cerr << '\n'; } template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){ cerr<<arg<<" ";Debug(rest...);} template<class T>ostream& operator<<(ostream& out,const vector<T>& v) { out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;} template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){ out<<"("<<v.first<<", "<<v.second<<")";return out;} const int MAX_N = 500010; const int MAX_V = 100010; const double eps = 1e-6; const ll mod = 1000000007; const int inf = 1 << 30; const ll linf = 1LL << 60; const double PI = 3.14159265358979323846; mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng) /////////////////////////////////////////////////////////////////////////////////////////////////// ll fac[MAX_N], inv[MAX_N], fiv[MAX_N]; //fiv:inv(fac(i)) ll mod_pow(ll a, ll n) { if(n == 0) return 1; ll res = mod_pow(a, n / 2); if(n % 2 == 0) return res * res % mod; else return a * res % mod * res % mod; } ll invf(ll a) { return mod_pow(a, mod - 2); } void C_init(int n) { fac[0] = fac[1] = 1; inv[1] = 1; fiv[0] = fiv[1] = 1; rep(i, 2, n + 1) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; fiv[i] = fiv[i - 1] * inv[i] % mod; } } ll C(int a, int b) { //assume a >= b if(a < b || a < 0 || b < 0) return 0; return fac[a] * fiv[b] % mod * fiv[a - b] % mod; } struct Ruiseki { int N; vector<ll> B; void init(int n) { N = n; B = vector<ll>(N + 1, 0); } Ruiseki() {} Ruiseki(int n) { init(n); } void add(int a, ll v) { if(a < 0 || N <= a) return; B[a + 1] += v; } void sweep() { rep(i, 1, N + 1) B[i] += B[i - 1]; } ll get(int a, int b) { //[a, b) if(a >= b) return 0; a = max(a, 0); b = min(b, N); return B[b] - B[a]; } }; int N; vector<int> G[1 << 20]; int A[MAX_N]; Ruiseki rui; void solve() { cin >> N; ll ans = 0; C_init(N); rui.init(N); rep(i, 0, N) cin >> A[i]; int sum = 0, cnt = 1; rep(i, 0, N) { sum ^= A[i]; if(sum == 0) { rui.add(i, 1); // debug(i); cnt++; } else G[sum].pb(i); } rui.sweep(); // debug(sum, cnt); if(sum == 0) { ADD(ans, mod_pow(2, cnt - 2)); } rep(i, 1, (1 << 20)) { if(sz(G[i]) == 0) continue; ll suma = 0, sumz = 1; // debug(G[i]); rep(j, 0, sz(G[i])) { // debug(i, j, suma, sumz); ll v = sumz; ADD(suma, v); if(j != sz(G[i]) - 1) { ll c = rui.get(G[i][j], G[i][j + 1]); ADD(sumz, suma * c % mod); // debug(G[i][j], G[i][j + 1], c); } } if(sum == 0) { ADD(ans, suma); } else if(sum == i) { ADD(ans, sumz); } } cout << ans << "\n"; } uint32_t rd() { uint32_t res; #ifdef __MINGW32__ asm volatile("rdrand %0" :"=a"(res) ::"cc"); #else res = std::random_device()(); #endif return res; } int main() { #ifndef LOCAL ios::sync_with_stdio(false); cin.tie(0); #endif cout << fixed; cout.precision(20); cerr << fixed; cerr.precision(6); rng.seed(rd()); #ifdef LOCAL //freopen("in.txt", "wt", stdout); //for tester freopen("in.txt", "rt", stdin); #endif solve(); cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0; }
#include<bits/stdc++.h> int main(){ using namespace std; constexpr unsigned long MOD = 1000000007; vector<unsigned long> tapi(1048576, 1), tapu(1048576), tape(1048576); unsigned long ans{0}, t{500000004}, a{0}, z{0}, A;cin >> A; while(cin >> A)if(a ^= A){ (tapu[a] += (tapi[a] += tapu[a] * (z - tape[a])) %= MOD) %= MOD; ans += tapi[a]; tape[a] = z; }else ++z, (t *= 2) %= MOD; cout << (a ? tapi[a] : (ans + t) % MOD) << endl; return 0; }
1
#define _CRT_SECURE_NO_WARNINGS // #define _USE_MATH_DEFINES #include <iostream> #include <cstdio> #include <algorithm> #include <string> #include <vector> #include <map> #include <set> #include <stack> #include <cmath> #include <cstdlib> #include <functional> #include <locale> #include <cctype> #include <sstream> #include <iomanip> // 10????????? cout << setprecision(10) << double; #include <queue> using namespace std; typedef long long LL; typedef vector<int> VI; typedef vector<VI> VVI; typedef map<int, int> MAPII; typedef multimap<int, char, greater<int> > MuMAPIC; typedef vector<pair<int, int> > VPII; typedef multimap<int, string, greater<int> > MuMIS; typedef pair<int, int> P; typedef pair<int, pair<P, P> > PP; #define MP make_pair #define FAST_IO cin.tie(0); ios::sync_with_stdio(false); #define FOR(i,a,b) for(int i=(a);i<(b);i++) //for gcc (???test) // #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it) //for Visual Studio #define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it) // for Debug. #define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");} #define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;} // ??\??????push_back(d)???array[d]???????????????1??????§????????? // int INPUT_INT() {int d;cin>>d;return d;} template<class T>T IN() { T d; cin >> d; return d; } // ??????§????¢??´????°???Greatest Common Divisor??? LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; } // ?????°?????¢??????°???Least Common Multiple??? LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // Y???´???????????????´????????? bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // vector???¨??? // vec[i][j]?????????????\????????\?????????¨??????vec???????????????????????????????????????. #define INF 1000000 // ????????????????°???????????????§??? // ------------------- include, typedef, define END. ------------------- int main() { int n = 0; while (cin >> n, n) { VI k(n + 1, 0); string s; FOR(i, 0, n) { k[i] = IN<int>(); } cin >> s; int j = -1; FOR(i, 0, s.length()) { j++; if (j >= n) { j = 0; } FOR(a, 0, k[j]) { s[i]--; if (s[i] == 96)s[i] = 90; if (s[i] == 64)s[i] = 122; } cout << s[i]; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef ostringstream OSS; typedef istringstream ISS; typedef long long LL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<VVI> VVVI; typedef vector<LL> VLL; typedef vector<VLL> VVLL; typedef vector<VVLL> VVVLL; typedef vector<double> VD; typedef vector<VD> VVD; typedef vector<VVD> VVVD; typedef vector<string> VS; typedef vector<VS> VVS; typedef vector<VVS> VVVS; typedef vector<bool> VB; typedef vector<VB> VVB; typedef vector<VVB> VVVB; typedef vector<PII> VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII; typedef vector<PLL> VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL; typedef unsigned int UI; typedef vector<UI> VUI; typedef vector<VUI> VVUI; #define fst first #define snd second // #define Y first // #define X second #define MP make_pair #define PB push_back #define EB emplace_back #define ALL(x) (x).begin(),(x).end() #define RALL(x) (x).rbegin(),(x).rend() #define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY)) #define RANGE(x, l, r) ((l) <= (x) && (x) <= (r)) #define rep(i, N) for (int i = 0; i < (int)(N); i++) #define rrep(i, N) for (int i = N - 1; i >= 0; i--) #define REP(i, init, N) for (int i = (init); i < (int)(N); i++) #define RREP(i, N, last) for (int i = (init - 1); i >= last; i--) #define MAXUD(orig, target) orig = max(orig, target) #define MINUD(orig, target) orig = min(orig, target) #define DUMP( x ) cerr << #x << " = " << ( x ) << endl template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; }; template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); }; template<typename T=int> inline void dump(vector<T> vs, bool ent=false) { rep(i, vs.size()) cout << vs[i] << (i+1==vs.size() ? '\n' : ' '); if (ent) cout << endl; } template<typename T = int> inline void dump(vector<vector<T>> vs, bool ent = false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; } const int INF = 0x3f3f3f3f; const LL INFL = 0x3f3f3f3f3f3f3f3fLL; const double DINF = 0x3f3f3f3f; const int DX[] = {1, 0, -1, 0}; const int DY[] = {0, -1, 0, 1}; const double EPS = 1e-12; // const double PI = acos(-1.0); // lambda: [](T1 x)->T2{return y;} // simple lambda: [](T x){return x;} string S; string solve(int N) { VI ks(N); rep(i, N) cin >> ks[i]; string s; cin >> s; string ans(s); int M = S.size(); rep(i, s.size()) { int p = i % (int)ks.size(); int pos = find(ALL(S), s[i]) - S.begin(); int pos2 = (pos - ks[p] + M) % M; ans[i] = S[pos2]; } return ans; } int main(void) { rep(i, 26) S += 'a' + i; rep(i, 26) S += 'A' + i; int N; while (cin >> N, N) cout << solve(N) << endl; return 0; }
1
#include <bits/stdc++.h> #define itn int #define REP(i, n) for (ll i = 0; i < n; i++) #define IREP(i, n) for (ll i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (ll i = a; i < b; i++) #define all(v) v.begin(), v.end() #define SENTINEL 2000000000 #define NIL -1 using namespace std; typedef long long ll; const ll MAX = 510000; const ll INF = 1LL << 60; const ll MOD = 1000000007; template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;} template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;} int main() { int n,k; cin >> n >> k; vector<int> a(n); REP(i,n){ cin >> a[i];; } REP(i,k){ vector<int> b(n, 0); REP(i, n) { int l = max(0LL, i - a[i]); int r = min(n - 1, int(i + a[i])); b[l]++; if (r + 1 < n) { b[r + 1]--; } } a[0]=b[0]; int ndesu=0; if(a[0]==n){ ndesu++; } REP(j, n) { if (j == 0) continue; b[j] += b[j - 1]; a[j]=b[j]; if(a[j]==n){ ndesu++; } } if(ndesu==n){ REP(j,n){ cout << n << " "; } cout << endl; return 0; } } REP(i,n){ cout << a[i] << " "; } cout << endl; }
#include <cstdio> #include <algorithm> using i8 = std::int8_t; using u8 = std::uint8_t; using i16 = std::int16_t; using u16 = std::uint16_t; using i32 = std::int32_t; using u32 = std::uint32_t; using i64 = std::int64_t; using u64 = std::uint64_t; using usize = std::size_t; i32 a[200000]; auto main() -> i32 { i32 n, k; scanf("%d%d", &n, &k); for (i32 i = 0; i < n; i += 1) { scanf("%d", a + i); } i32 b[200001]; for (i32 step = 0; step < std::min(64, k); step += 1) { std::fill(b, b + n + 1, 0); for (i32 i = 0; i < n; i += 1) { b[std::max(0, i - a[i])] += 1; b[std::min(n, i + a[i] + 1)] -= 1; } a[0] = b[0]; for (i32 i = 1; i < n; i += 1) { b[i] += b[i - 1]; a[i] = b[i]; } } for (i32 i = 0; i < n; i += 1) { printf("%d%c", a[i], i == n - 1 ? '\n' : ' '); } return 0; }
1
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < n; i++) #define repr(i, n) for(int i = n; i >= 0; i--) #define reps(i,a,b) for(int i= a; i < b; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() using namespace std; typedef long long ll; int main() { int n; string s; cin >> n >> s; ll r = 0, b = 0, g = 0; rep(i, n) { if (s.at(i) == 'R') { r++; continue; } if (s.at(i) == 'G') { g++; continue; } if (s.at(i) == 'B') { b++; continue; } } ll ans = r * b * g; if (!ans) { cout << 0 << endl; return 0; } rep(i, n) { reps(j, i+1, n) { if (s.at(i) == s.at(j)) continue; int k = 2*j - i; if (k >= n) continue; if ((s.at(i) != s.at(j)) && (s.at(i) != s.at(k)) && (s.at(k) != s.at(j))) { ans--; } } } cout << ans << endl; return 0; }
#pragma GCC optimize("Ofast") #define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; using u8 = uint8_t; using u16 = uint16_t; using u32 = uint32_t; using u64 = uint64_t; using i8 = int8_t; using i16 = int16_t; using i32 = int32_t; using i64 = int64_t; constexpr char newl = '\n'; constexpr double eps = 1e-10; #define FOR(i,a,b) for (int i = (a); i < (b); i++) #define F0R(i,b) FOR(i,0,b) #define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--) #define RF0(i,b) RFO(i,0,b) #define fi first #define se second #define debug(x) cout << #x << ": " << x << '\n'; #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; } template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; } template<class T> void Print(vector<T> v) { F0R(i, v.size()) { cout << v[i] << ' '; } cout << newl; } #if 1 // INSERT ABOVE HERE signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int N, L; cin >> N >> L; int l = L, r = L + N - 1; int sum = (l+r) * N / 2; if (l > 0) { sum -= l; } else if (r < 0) { sum -= r; } cout << sum; } #endif
0
#include<iostream> #include<algorithm> #include<vector> #include<queue> using namespace std; int N_MAX=100001; long long INF = 123456789123456789; typedef pair<long long,int> P; void dijkstra(int s, int V, vector<P>* g, long long* d){ if(d[s]==0) return; int i,v; P p,e; priority_queue<P, vector<P>, greater<P>> que; // 最短距離,頂点番号 fill(d,d+V,INF); d[s]=0; que.push(P(0,s)); while(!que.empty()){ p=que.top(); que.pop(); v=p.second; if(d[v]<p.first) continue; for(i=0;i<g[v].size();i++){ e=g[v][i]; if(d[e.second]>d[v]+e.first){ d[e.second]=d[v]+e.first; que.push(P(d[e.second],e.second)); } } } return; } int main() { int n,q,k,x,y,a,b,i; long long c; long long d[N_MAX]; vector<P> g[N_MAX]; cin >> n; fill(d+1,d+n+1,INF); for(i=0;i<n-1;i++){ cin >> a >> b >> c; g[a].emplace_back(c,b); g[b].emplace_back(c,a); } cin >> q >> k; dijkstra(k,n,g,d); for(i=0;i<q;i++){ cin >> x >> y; cout << d[x]+d[y] << endl; } return 0; }
#include "bits/stdc++.h" using namespace std; int dp(int curr, int T, const vector<int>& A, const vector<int>& B, vector<vector<int>>& memo) { int N = A.size(); if (curr == N) { return 0; } if (T <= 0) { return 0; } if (memo[curr][T] >= 0) { return memo[curr][T]; } int skip = dp(curr + 1, T, A, B, memo); int take = dp(curr + 1, T - A[curr], A, B, memo) + B[curr]; int ret = max(skip, take); memo[curr][T] = ret; return ret; } void Main() { int N, T; cin >> N >> T; set<pair<int, pair<int, int>>> prep; for (int i = 0; i < N; ++i) { int a, b; cin >> a >> b; prep.insert(make_pair(a, make_pair(i, b))); } vector<int> A(N, 0), B(N, 0); int cnt = 0; for (auto e : prep) { A[cnt] = e.first; B[cnt] = e.second.second; ++cnt; } vector<vector<int>> memo(N + 10, vector<int>(T + 10, -1)); int ans = dp(0, T, A, B, memo); cout << ans << endl; } int main() { std::cout << std::fixed << std::setprecision(15); Main(); return 0; }
0
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array int a,b; void solve(){ cin >> a >> b; cout << a*b << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); solve(); }
#include <bits/stdc++.h> using namespace std; int main() { int A,B,i,ans=0,p,q,r,s; cin >> A >> B; for(i=A;i<=B;i++){ p=i%10; q=(i/10)%10; r=(i/1000)%10; s=(i/10000)%10; if(p==s&&q==r){ ans++; } } cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; string s; cin >> s; string t = ""; for (int i = 0; i < 2; i++){ for (int j = 0; j < 2; j++){ string tmp; if (i == 0){ tmp += 'S'; } else { tmp += 'W'; } if (j == 0){ tmp += 'S'; } else { tmp += 'W'; } for (int k = 2; k < N; k++){ if ((tmp[k - 1] == 'S') ^ (s[k - 1] == 'o') ^ (tmp[k - 2] == 'S')){ tmp += 'S'; } else { tmp += 'W'; } } bool ok = true; if ((tmp[N - 2] == 'S') ^ (tmp[N - 1] == 'S') ^ (tmp[0] == 'S') ^ (s[N - 1] == 'o')){ ok = false; } if ((tmp[N - 1] == 'S') ^ (tmp[0] == 'S') ^ (tmp[1] == 'S') ^ (s[0] == 'o')){ ok = false; } if (ok){ t = tmp; } } } if (t == ""){ cout << -1 << endl; } else { cout << t << endl; } }
#include <bits/stdc++.h> #define debug(x) cerr<<#x<<'='<<x<<endl #define set0(x) memset(x,0,sizeof(x)) using namespace std; typedef long long ll; typedef pair<ll,ll> pii; template<typename T> void read(T &x){ x = 0;char ch = getchar();ll f = 1; while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();} while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f; } char str[305]; int dp[305][305][305]; void upd(int &a,int b){ a =max(a,b); } int main() { cin>>(str+1); int n = strlen(str+1); int lim; cin>>lim; int ans = 0; for(int i=1;i<=n;i++){ for(int j=n;j>=1;j--){ for(int k=0;k<=lim;k++){ upd(dp[i+1][j][k],dp[i][j][k]); upd(dp[i][j-1][k],dp[i][j][k]); if(str[i] == str[j]){ upd(dp[i+1][j-1][k],dp[i][j][k]+1); }else{ upd(dp[i+1][j-1][k+1],dp[i][j][k]+1); } } } } for(int i=0;i<=n+1;i++){ for(int j=n+1;j>=0;j--){ for(int k=0;k<=lim;k++){ if(i == j+1)ans = max(ans,dp[i][j][k]*2); if(i-1 == j+1)ans = max(ans,dp[i][j][k]*2-1); } } } cout<<ans<<endl; return 0; }
0
#include <iostream> #include <algorithm> #include <string> using namespace std; int n; int a[50001]; int S[50001]; int main(){ while(cin >> n && n > 0){ for (int i = 0; i < n; ++i) { cin >> a[i]; } S[0] = 0; for (int i = 0; i < n ; ++i) { S[i + 1] = S[i] + a[i]; } int max = -100000; for (int i = 0; i < n + 1; ++i) { for (int k = 0; k < i ; ++k) { if(S[i] - S[k] > max) max = S[i] - S[k]; } } cout << max << endl; } }
#include <iostream> #include <utility> #include <vector> #include <cmath> #include <algorithm> using namespace std; #define gcu getchar_unlocked #define pcu putchar_unlocked #define _il inline #define _in _il int in #define _sc _il bool scan _in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu(); do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9' _in() {return in(gcu());} _sc(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);} _sc(char &c){c=gcu();gcu();return c!=EOF;} //_sc(string &s){int c;s=""; // for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}} template <typename H,typename... T> _sc(H &h, T&&... t){return scan(h)&&scan(t...);} #define _vo _il void out #define _vl _il void outl template <typename T> _vo(T n){static char buf[20];char *p=buf; if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10; while (p!=buf)pcu(*--p);} _vo(const char *s){while(*s)pcu(*s++);} _vo(char c){pcu(c);} //_vo(string &s){for (char c: s) pcu(c);} template <typename H,typename... T> _vo(H&& h, T&&... t){out(h);out(move(t)...);} //template <typename T> _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');} _vl(){out('\n');} template <typename... T> _vl(T&&... t){out(move(t)...);outl();} template<int N> struct sieve { bool s[N]; constexpr sieve() : s() { for (int i = 0; i < N; i++) s[i] = true; for (int i = 4; i < N; i += 2) s[i] = false; for (int i = 9; i < N; i += 6) s[i] = false; for (int i = 6, e = sqrt(N); i <= e; i += 6) { for (int j : {i - 1, i + 1}) if (s[j]) for (int k = j * j; k < N; k += j) s[k] = false; } } }; int main() { enum {N = 10001}; constexpr sieve<N> s; vector<int> t = {5}; for (int i = 7; i < N; i += 6) if (s.s[i - 2] && s.s[i]) t.push_back(i); for (int n; (n = in());) { auto r = upper_bound(t.begin(), t.end(), n) - 1; outl(*r - 2, ' ', *r); } }
0
#include<iostream> using namespace std; int main(){ int tuki[13]={0,0,31,60,91,121,152,182,213,244,274,305,335}; string cal[400]; cal[1]="Thursday";cal[2]="Friday";cal[3]="Saturday";cal[4]="Sunday"; cal[5]="Monday";cal[6]="Tuesday";cal[7]="Wednesday"; for(int i=1;i<=366;i++) cal[i+7]=cal[i]; int a,b; while(cin>>a>>b,a+b) cout<<cal[tuki[a]+b]<<endl; return 0; }
#include<stdio.h> int main() { int p[12]={31,29,31,30,31,30,31,31,30,31,30,31}; int M,D,sum; while(1) { sum=0; scanf("%d",&M); scanf("%d",&D);if(M==0)break; if(M==0)break; for(int i=0;i<M-1;i++) sum+=p[i]; sum+=D; switch(sum%7) { case 4: printf("Sunday\n");break; case 5: printf("Monday\n");break; case 6: printf("Tuesday\n");break; case 0: printf("Wednesday\n");break; case 1: printf("Thursday\n");break; case 2: printf("Friday\n");break; case 3: printf("Saturday\n");break; } } return 0; }
1
#include <bits/stdc++.h> using namespace std; using pp=pair<int,int>; int main() { string S; cin >> S; string ans="AC"; if (S[0]!='A') {ans="WA";} int c=0, ci; for (int i=2; i<S.size()-1; i++) { if (S[i]=='C') { c++; ci=i; } } if (c!=1) {ans="WA";} for (int i=0; i<S.size(); i++) { if (i==0 || i==ci) {continue;} if (S[i]-'Z'<=0) { ans="WA"; break; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int count = 0; map<int, int> mp; for (int i = 0; i < 3; i++) { int a; cin >> a; if (mp[a]) count++; mp[a] = 1; } if (count == 1) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { cin.tie(0); ios::sync_with_stdio(0); ll n,a,b,c,d,e;cin>>n>>a>>b>>c>>d>>e; ll s=min(min(min(min(a,b),c),d),e); ll ans=(n-1)/s+5; cout<<ans<<"\n"; return 0; }
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <queue> #include <bitset> #include <stack> #include <functional> #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define eprintf(...) 42 #endif #define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i) #define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i) #define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define all(x) (x).begin(), (x).end() template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } // template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair <int,int> P; typedef long double ld; int main (void) { cin.tie(0); ios::sync_with_stdio(false); ld n, m, d; cin >> n >> m >> d; printf("%.16Lf\n", (d == 0 ? 1.0 : 2.0) * (n - d) * (m - 1.0) / (n * n)); return 0; }
0
#include <bits/stdc++.h> using namespace std; using lint = long long; const lint mod = 1e9 + 7; #define all(x) (x).begin(), (x).end() #define bitcount(n) __builtin_popcountl((lint)(n)) #define fcout cout << fixed << setprecision(15) #define highest(x) (63 - __builtin_clzl(x)) template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; } template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; } template<class T> inline void assert_NO(T condition){ if(!condition){ cout << "NO" << endl; exit(0); } } template<class T> inline void assert_No(T condition){ if(!condition){ cout << "No" << endl; exit(0); } } template<class T> inline void assert_minus_1(T condition){ if(!condition){ cout << -1 << endl; exit(0); } } lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }} struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); } template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; } template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; } template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } } template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }} template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); } template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; } struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } }; template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; } template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b){ if(b < a){ a = b; return 1; } return 0; } inline int at(int x, int k){ return (x >> k) & 1; } random_device rnd; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep2(i, l, n) for(int i = int(l); i < (n); i++) #define repr(i, n) for(int i = int(n) - 1; i >= 0; i--) int main(){ string a; cin >> a; lint sz = a.size(), ans = sz * (sz + 1) / 2; for(char i = 'a'; i <= 'z'; i++){ sz = count(all(a), i); ans -= sz * (sz + 1) / 2; } cout << ans + 1 << endl; }
#include<iostream> #include<algorithm> #include<vector> #include<string> #include<utility> #include<map> #include<set> #include<queue> #include<stack> #include<functional> #include<math.h> using namespace std; #define N (1000000000+7) #define INF 1e16 typedef long long ll; typedef pair<ll,ll> P; int main(void){ ll n; string s; cin>>n; cin>>s; ll ans = 1; ll num = 0; for(ll i=0;i<2*n;i++){ if((2*n-1-i)%2==1){ if(s[i]=='B')num++; else{ ans = ans*num; ans = ans%N; num--; } } else{ if(s[i]=='W')num++; else{ ans = ans*num; ans = ans%N; num--; } } } if(num!=0){ cout<<0<<endl; return 0; } for(ll i=1;i<=n;i++){ ans = ans*i; ans = ans%N; } cout<<ans<<endl; return 0; }
0
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <complex> #include <cstring> #include <cstdlib> #include <string> #include <cmath> #include <queue> using namespace std; #define REP(i,n) for(int i=0;i<(int)n;++i) #define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i) #define ALL(c) (c).begin(), (c).end() const int INF = 1<<29; int main() { int n,m; while(cin>>n>>m, n+m) { int p[n]; REP(i,n) cin >> p[i]; vector<int> v(n*n); REP(i,n) REP(j,n) v[i*n + j] = p[i] + p[j]; v.push_back(0); REP(i,n) v.push_back(p[i]); sort(ALL(v)); // FOR(it, v) // cout << *it << " "; // cout << endl; int res = 0; REP(i,v.size()) { vector<int>::iterator it = upper_bound(ALL(v), m-v[i]); int tmp; if (it == v.begin()) { break; } else { it--; tmp = v[i] + *it; } res = max(res, tmp); } cout << res << endl; } }
#include <iostream> #include <algorithm> using namespace std; int main() { while(true){ int n, k, x, a, b, fee[101][101]; cin >> n >> k; if(n == 0 && k == 0){ break; } for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ fee[i][j] = 1000000000; } } for(int i = 0; i < k; i++){ cin >> x >> a >> b; if(x){ cin >> fee[a][b]; fee[b][a] = fee[a][b] = min(fee[a][b], fee[b][a]); for(int j = 1; j <= n; j++){ for(int l = 1; l <= n; l++){ fee[j][l] = min(fee[j][l], fee[j][a] + fee[a][l]); fee[l][j] = fee[j][l] = min(fee[j][l], fee[j][b] + fee[b][l]); } } } else{ if(fee[a][b] != 1000000000){ cout << fee[a][b] << endl; } else{ cout << -1 << endl; } } } } return 0; }
0
#include <cstdio> #include <iostream> #include <string> using namespace std; int main() { int n = 0, tmp0 = 0, tmp1 = 0; int tmp2 = 0, tmp3, out1 = 0, out2 = 0; int a[100]; scanf("%d", &n); while (n) { for (tmp3=0;tmp3<100;tmp3++) a[tmp3] = 0; tmp0 = 0, out2 = 0; while (tmp0 < n) { tmp1 = 0, out1 = 0; while (tmp1 < n) { scanf("%d", &tmp2); a[tmp1] += tmp2; printf("%5d", tmp2); out1 += tmp2; tmp1++; } printf("%5d\n", out1); a[tmp1] += out1; tmp0++; } tmp0 = 0; while (tmp0 < n) { printf("%5d", a[tmp0]); tmp0++; } printf("%5d\n", a[tmp0]); scanf("%d", &n); } return 0; }
#include <stack> #include <queue> #include <cstdlib> #include <iomanip> #include <utility> #include <math.h> #include <vector> #include <algorithm> #include <string> #include <iostream> using namespace std; int main() { int n; while(cin >> n && n != 0) { int a[11][11]; for(int i = 0;i < n;i++) { for(int j = 0; j<n;j++) { cin >> a[i][j]; } } for(int i = 0; i<n;i++) { a[i][n] = 0; a[n][i] = 0; for(int j = 0;j < n;j++) { a[i][n] += a[i][j]; a[n][i] += a[j][i]; } } a[n][n] = 0; for(int i = 0;i<n;i++) { a[n][n] += a[i][n]; } for(int i = 0; i< n+1;i++) { for(int j = 0; j<n+1;j++) { cout << setw(5) << right << a[i][j]; } cout <<endl; } } return 0; }
1
#include <iostream> #include <iomanip> #include <vector> #include <set> #include <string> #include <queue> #include <algorithm> #include <map> #include <cmath> #include <numeric> #include <list> #include <stack> #include <cstdio> #include <cstdlib> #include <cstring> #include <tuple> #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i <= (n); i++) #define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl #define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} #define chmin(a, b) a = min(a, b) #define chmax(a, b) a = max(a, b) using namespace std; typedef vector<int> vi; typedef pair<int, int> pii; typedef long long ll; typedef vector<ll> vll; typedef pair<long long, long long> pll; typedef long double ld; const int INF = 1 << 30; const long long INFL = 1LL << 60; const int MOD = 1000000007; const int MAX = 100000; const int N = 100010; int main() { // cout << fixed << setprecision(15); ll m; cin >> m; vll d(m), c(m); rep(i, m) cin >> d[i] >> c[i]; ll sumc = 0; ll sumd = 0; rep(i, m) sumc += c[i]; rep(i, m) sumd += c[i] * d[i]; cout << sumc - 1 + (sumd - 1) / 9 << endl; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; int solve(int n, vector<int> & dims){ int dp[100][101] = {{0}}; for (int span = 2; span != n + 1; ++span){ for (int first = 0; first + span != n + 1; ++first){ for (int last = first + span; last != n + 1; ++last){ int record = 2000000000; for (int mid = first + 1; mid != last; ++mid){ record = min(record, dp[first][mid] + dp[mid][last] + dims[first] * dims[last] * dims[mid]); } dp[first][last] = record; } } } return dp[0][n]; } int main() { int n = 0; cin >> n; vector<int> dims(n + 1); int r = 0; int c = 0; for (int i = 0; i != n; ++i){ cin >> r >> c; dims[i] = r; } dims[n] = c; cout << solve(n, dims) << endl; return 0; }
0
#include<iostream> #include<string> using namespace std; int data[7]; void N(){int x=data[5];data[5]=data[1];data[1]=data[2];data[2]=data[6];data[6]=x;} void S(){int x=data[5];data[5]=data[6];data[6]=data[2];data[2]=data[1];data[1]=x;} void E(){int x=data[3];data[3]=data[1];data[1]=data[4];data[4]=data[6];data[6]=x;} void W(){int x=data[4];data[4]=data[1];data[1]=data[3];data[3]=data[6];data[6]=x;} int main(){ string com; for(int i=1;i<=6;++i)cin>>data[i]; getline(cin,com); getline(cin,com); for(auto ch:com){ if(ch=='N')N(); if(ch=='S')S(); if(ch=='E')E(); if(ch=='W')W(); } cout<<data[1]<<endl; return 0; }
#include <iostream> #include <bits/stdc++.h> #include <string> #include <ctype.h> #include <algorithm> #include <cmath> #define REP(i, n) for(int i=0;i<(int)(n);i++) #define ALL(x) (x).begin(),(x).end() #define square(x) (x) * (x) #define cube(x) (x) * (x) * (x) const int INF = 1e9; using namespace std; class dice{ private: int s[6]; int top; int bottom; int r_side; int l_side; int face; int rev; public: dice(){ top = 0; bottom = 5; r_side = 2; l_side = 3; face = 1; rev = 4; s[0] = 1; s[1] = 2; s[2] = 3; s[3] = 4; s[4] = 5; s[5] = 6; } dice(int a[5]){ top = 0; bottom = 5; r_side = 2; l_side = 3; face = 1; rev = 4; REP(i, 6) s[i] = a[i]; } dice(int x, int y, int z, int u, int v, int w){ top = 0; bottom = 5; r_side = 2; l_side = 3; face = 1; rev = 4; s[0] = x; s[1] = y; s[2] = z; s[3] = u; s[4] = v; s[5] = w; } int get_top() { return s[top]; } int get_bottom(){ return s[bottom]; } int get_r_side(){ return s[r_side]; } int get_l_side(){ return s[l_side]; } int get_face(){ return s[face]; } int get_rev(){ return s[rev]; } int set_top(int i) { top = i; bottom = 5 - top; r_side = (i+1)%5; l_side = 5 - r_side; face = (i+2)%5; rev = 5 - face; return s[top]; } int rotate_r(int i) { while(i<0) i+=4; i %= 4; REP(j, i){ int temp = face; face = r_side; r_side = rev; rev = l_side; l_side = temp; } return s[top]; } int roll_r(int i) { while(i<0) i+=4; i %= 4; REP(j, i){ int temp = top; top = l_side; l_side = bottom; bottom = r_side; r_side = temp; } return s[top]; } int roll_f(int i){ while(i<0) i+=4; i %= 4; REP(j, i){ int temp = top; top = face; face = bottom; bottom = rev; rev = temp; } return s[top]; } }; int main() { int in[6]; REP(i, 6) cin >> in[i]; dice d = dice(in); string roll; cin >> roll; while(roll.size() != 0){ string order = roll.substr(0, 1); if(order == "E") d.roll_r(1); else if(order == "S") d.roll_f(-1); else if(order == "N") d.roll_f(1); else if(order == "W") d.roll_r(-1); roll = roll.substr(1); } cout << d.get_top() << endl; return 0; }
1
#include<bits/stdc++.h> using namespace std; #define INF (1<<29)//INF #define F first #define S second #define VS vector<string> #define VI vector<int> #define REPI(i,s,n) for(int i=s;i<n;i++)//sからn未満の間iを回す #define REPJ(j,s,n) for(int j=s;j<n;j++)//sからn未満の間iを回す #define RREPI(i,s,n) for(int i=s;i>=n;i--)//sからn以下の間iを回す #define RREPJ(j,s,n) for(int j=s;j>=n;j--)//sからn以下の間jを回す #define ALL(a) a.begin(),a.end()//ソートとかに使える sort(ALL(vec))のように #define SET(a,c) memset(a,c,sizeof(a));//aをc(0or1)で初期化する #define DEBUGONE(x) cout<<#x<<" : "<<x<<endl;//デバックで一つの変数を表示 #define DEBUGTWO(x,y) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl;//デバックで二つの変数を表示 #define DEBUGTHREE(x,y,z) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl;//デバックで三つの変数を表示 #define OUTONE(x) cout<<x<<endl;//一つの変数を表示 #define OUTTWO(x,y) cout<<x<<" "<<y<<endl;//二つの変数を表示 #define OUTTHREE(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;//三つの変数を表示 typedef long long int64; typedef pair<string,int> Psi; typedef pair<int,int> Pii; map<Psi,int64> mem; string num[15]; int n,k; int64 ans=0; int64 bitdfs(int now,string nows,int bits); main(){ while(cin>>n>>k,n||k){ ans=0; mem.clear(); REPI(i,0,n){ cin>>num[i]; } cout<<bitdfs(0,"",0)<<endl; } } int64 bitdfs(int now,string nows,int bits){ if(now>=k){ if(mem[Psi(nows,now)]==0){ mem[Psi(nows,now)]=-1; return 1; } else{ return 0; } } else{ int64 cnt=0; int bitst=1; REPI(i,0,n){ int b=bitst&bits; if(b==0){ cnt+=bitdfs(now+1,nows+num[i],bits|bitst); } bitst=bitst<<1; } return mem[Psi(nows,now)]=cnt; } }
#include <bits/stdc++.h> using namespace std; #define INF (1<<29) set<string> st; void solve(int K, int S, vector<string> &s, string str) { if (K == 0) { st.insert(str); return; } int N = s.size(); for (int i = 0; i < N; i++) { if (S >> i & 1) continue; solve(K-1, S|(1<<i), s, str + s[i]); } } int main() { int N, K; while (cin >> N, N) { vector<string> s(N); cin >> K; for (int i = 0; i < N; i++) { cin >> s[i]; } st.clear(); solve(K, 0, s, ""); cout << st.size() << endl; } return 0; }
1
#include "bits/stdc++.h" using namespace std; #ifndef LOCAL #define endl '\n' #endif #define fr(i, a, b) for(int i = a; i <= b; i++) #define rf(i, a, b) for(int i = a; i >= b; i--) #define pf push_front #define pb push_back #define eb emplace_back #define fi first #define se second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) (int)x.size() #define lb lower_bound #define ub upper_bound typedef long long ll; typedef long double f80; typedef pair<int,int> pii; typedef pair<ll,ll> pll; int pct(int x) { return __builtin_popcount(x); } int pct(ll x) { return __builtin_popcountll(x); } int bt(int x) { return 31 - __builtin_clz(x); } // floor(log2(x)) int bt(ll x) { return 63 - __builtin_clzll(x); } // floor(log2(x)) int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); } ll cdiv(ll a, ll b) { return a / b + !(a < 0 || a % b == 0); } int nxt_C(int x) { int c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; } ll nxt_C(ll x) { ll c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; } vector<int> get_bits(int mask) { vector<int> bb; while(mask) { int b = bt(mask); bb.pb(b); mask ^= (1 << b); } reverse(all(bb)); return bb; } int get_mask(vector<int> v) { int mask = 0; for(int x : v) { mask ^= (1 << x); } return mask; } template<typename T> void uniq(vector<T> &v) { sort(all(v)); v.resize(unique(all(v)) - v.begin()); } mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r){ uniform_int_distribution<ll> uid(l, r); return uid(rng); } void sc() {} template <typename Head, typename... Tail> void sc(Head &H, Tail &... T) { cin >> H; sc(T...); } #ifdef LOCAL #define debug(...) cerr << "[L:" << __LINE__ << "][" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif // #ifndef LOCAL // string to_string(__int128 x) { // string s = ""; // bool neg = 0; // if(x < 0) { s += "-"; neg = 1; x = -x; } // if(!x) s += '0'; // while(x) { // int rem = x % 10; // s += to_string(rem); // x /= 10; // } // reverse(s.begin() + neg, s.end()); // return s; // } // #endif const int mod = 1e9 + 7; // 998244353; int pwr(int a,ll b) { int ans = 1; while(b) { if(b & 1) ans = (ans * 1LL * a) % mod; a = (a * 1LL * a) % mod; b >>= 1; } return ans; } /* Lookout for overflows!! Check array sizes!! Clear before test cases!! Use the correct modulo!! Check for corner cases!! Are you forgetting something?! Read problem statement carefully!!! */ const int N = 1e5 + 5; int dsu[N], sz[N]; bool odd[N], par[N]; int root(int u) { while(u != dsu[u]) u = dsu[u]; return u; } int get_par(int u) { int p = 0; while(u != dsu[u]) { p ^= par[u]; u = dsu[u]; } return p; } void uni(int u,int v) { int uu = root(u), vv = root(v); if(uu == vv) { if(get_par(u) == get_par(v)) odd[uu] = 1; return; } if(sz[uu] > sz[vv]) { swap(uu, vv), swap(u, v); } dsu[uu] = vv; sz[vv] += sz[uu]; odd[vv] |= odd[uu]; par[uu] = get_par(u) ^ get_par(v) ^ 1; } void solve() { int n, m; sc(n, m); fr(i, 1, n) { sz[i] = 1; dsu[i] = i; odd[i] = 0; par[i] = 0; } fr(i, 1, m) { int u, v; sc(u, v); uni(u, v); } int c1 = 0, c2 = 0, c3 = 0; fr(i, 1, n) { if(i == dsu[i]) { if(sz[i] == 1) { c1++; } else if(odd[i]) { c2++; } else { c3++; } } } ll ans = 0; while(c1) { ans += 2 * n - 1; n--; c1--; } while(c2) { ans += 2 * (c2 + c3) - 1; c2--; } ans += (c3 * 1LL * (c3 - 1)) * 2 + 2LL * c3; cout << ans; } int main() { ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; for(int tt = 1; tt <= t; tt++) { solve(); } return 0; }
#include<bits/stdc++.h> #define pb push_back #define mp make_pair #define se second #define fi first #define _ std::ios_base::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0); using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; const int mod = 1e9+7; const int LOG = 17; const int N = 5e5+123; const ll INF = (ll)1e18 + 7; int dp[10010][110]; int main() { string s; cin >> s; int d; cin >> d; dp[0][0] = 1; for (int i = 0; i < s.size(); i++) { for (int j = 0; j < d; j++) { for (int k = 0; k <= 9; k++) { dp[i + 1][(j + k) % d] += dp[i][j]; dp[i + 1][(j + k) % d] %= mod; } } } int sum = 0; int ans = 0; for (int i = 0; i < s.size(); i++) { for (int j = 0; j < s[i] - '0'; j++) { ans += dp[(int)s.size() - i - 1][(d - (sum + j) % d) % d]; ans %= mod; } sum += s[i] - '0'; } if (sum % d == 0) { ans++; } ans += mod - 1; ans %= mod; cout << ans; return 0; }
0
#include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; int main(){ int N,X,T; cin >> N >> X >> T; int ans = N/X; double mod = N%X; if(mod > 0){ ans = ans + 1; } ans = ans * T; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back const int mod=1e9+7; const int N=1e6+10; void read(int &a) { a=0;int d=1;char ch; while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1; a=ch^48; while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48); a*=d; } void read(ll &a) { a=0;int d=1;char ch; while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1; a=ch^48; while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48); a*=d; } int main() { int n,x,t; read(n),read(x),read(t); if(n%x==0) printf("%d\n",n/x*t); else printf("%d\n",(n/x+1)*t); return 0; }
1
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll,ll>; using pii = pair<int,int>; #define ALL(x) (x).begin(),(x).end() int main(){ ll K; cin >> K; ll N = 50; vector<ll> A(N); // K/N周回す for(int i=0;i<N;i++) { A[i] = (N-1) + K/N; } // あまりの処理 ll d = K % N; for(int i=0;i<d;i++) { A[i] += N; for(int j=0;j<N;j++) { if(i == j) continue; A[j]--; } } cout << N << endl; for(int i=0;i<N;i++) cout << A[i] << ((i == N-1) ? "\n" : " "); }
#include <iostream> #include <algorithm> #include <vector> #include <map> #include <set> #include <string> #include <cmath> #include <iomanip> #include <queue> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cassert> #include <cstring> #include <climits> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define SORT(c) sort((c).begin(), (c).end()) #define mp make_pair #define fi first #define se second #define pb push_back typedef long long ll; typedef pair<int, int> P; typedef vector<int> V; typedef map<int, int> M; constexpr ll INF = 1e18; constexpr ll MOD = 1e9 + 7; constexpr double PI = 3.14159265358979323846; constexpr int di[] = {0, 0, 1, -1}; constexpr int dj[] = {1, -1, 0, 0}; int main() { ios::sync_with_stdio(false); cin.tie(0); ll k; cin >> k; ll n = (k + 49) / 50; ll m = (50 - (k % 50)) % 50; cout << 50 << endl; ll a[50]; REP(i, 50) a[i] = 49 + n; REP(i, m) { sort(a, a + 50); REP(j, 49) a[j]++; a[49] -= 50; } REP(i, 50) cout << a[i] << endl; return 0; }
1
#include <stdio.h> int main(){ int H1,H2,M1,M2,K; scanf("%d %d %d %d %d",&H1,&M1,&H2,&M2,&K); int sum1 = (H1*60) + M1; int sum2 = (H2*60) + M2; int sum3 = sum2 - sum1; printf("%d", sum3 - K); return 0; }
// // nomura_a.cpp // learningCplusplus // // Created by Tran Duc Chinh on 2020/04/04. // Copyright © 2020 Tran Duc Chinh. All rights reserved. // #include <iostream> #include <queue> #include <map> #include <algorithm> #include <math.h> using namespace std; typedef long long ll; ll mod = 998244353; ll INF = 1000000007; #define PI 3.14159265 pair<int, int> dijsktra(int x, char des, int n, vector<pair<int, char> > *adj) { priority_queue<pair<pair<int, char>, int> > q; // (-d, x) current distance to node x is d, using -d to find minimum distance bool processed[n]; pair<int, char> distance[n]; for (int i=0; i<n; i++) { distance[i].first = INF; distance[i].second = '0'; processed[i] = false; } // find from x distance[x] = make_pair(0, '0'); q.push({distance[x], x}); while (!q.empty()) { int a = q.top().second; q.pop(); if (processed[a]) continue;; processed[a] = true; for (auto u: adj[a]) { int b = u.first; // node b char label = u.second; int w = 1; // distance from a to b is w if (distance[b].first > distance[a].first + w) { distance[b] = make_pair(distance[a].first + w, label); q.push({{-distance[b].first, label}, b}); } } } int l = INF; int end = 0; // std::cout << "distance from " << x << std::endl; for (int i = 0; i < n; i++) { if (distance[i].first==INF) continue; if (distance[i].second == des && distance[i].first < l) { l = distance[i].first; end = i; } // std::cout << " distance to " << i << ": " << distance[i] << std::endl; } return make_pair(l, end); } int main() { int h1, m1, h2, m2, k; cin >> h1 >> m1 >> h2 >> m2 >> k; std::cout << h2*60+m2 - (h1*60+m1) - k << std::endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < n; i++) #define REPR(i, n) for(int i = n; i >= 0; i--) #define FOR(i, m, n) for(int i = m; i < n; i++) #define ALL(obj) (obj).begin(), (obj).end() #define INF 1e9 typedef long long ll; int main() { int N,Q; cin >> N >> Q; string S; cin >> S; vector<int> AC(N,0); FOR(i,1,N){ if(S[i-1]=='A' && S[i]=='C'){ AC[i] += 1; } AC[i] += AC[i-1]; } REP(i,Q){ int l,r; cin >> l >> r; l--; r--; cout << AC[r] - AC[l] << endl; } return 0; }
#include<iostream> // Need start #include<vector> #include<algorithm> #include<functional> // Need end #include<cmath> #include<iomanip> using namespace std; // Copy start template<typename T> class Polygon2D { private: T x_, y_; int idx_; public: Polygon2D() {} Polygon2D(T x, T y):x_(x), y_(y) {} Polygon2D(T x, T y, int idx):x_(x), y_(y), idx_(idx) {} // for convex-full static T dot(const Polygon2D<T>& p1, const Polygon2D<T>& p2) {return p1.x_ * p2.x_ + p1.y_ * p2.y_;} static T det(const Polygon2D<T>& p1, const Polygon2D<T>& p2) {return p1.x_ * p2.y_ - p1.y_ * p2.x_;} static T pow(const Polygon2D<T>& p) {return dot(p, p);} const Polygon2D operator=(const Polygon2D<T>& p) {x_ = p.x_; y_ = p.y_; idx_ = p.idx_; return *this;} const Polygon2D operator+(const Polygon2D<T>& p) const {Polygon2D<T> res = *this; res.x_ += p.x_; res.y_ += p.y_; return res;} const Polygon2D operator-(const Polygon2D<T>& p) const {Polygon2D<T> res = *this; res.x_ -= p.x_; res.y_ -= p.y_; return res;} T getX() const {return x_;} T getY() const {return y_;} int getIdx() const {return idx_;} friend ostream& operator<<(ostream& stream, const Polygon2D& p) {stream << '(' << p.x_ << ',' << p.y_ << ')'; return stream;} }; // Graham's scan template<typename T> vector<Polygon2D<T> > convex_hull(vector<Polygon2D<T> > ps, int vertex_num) { sort(ps.begin(), ps.end(), [](const Polygon2D<T>& p, const Polygon2D<T>& q) { if (p.getX() != q.getX()) return p.getX() < q.getX(); return p.getY() < q.getY(); }); int k = 0; vector<Polygon2D<T> > qs(vertex_num * 2); // bottom for (int i = 0; i < vertex_num; i++) { while (k > 1 && Polygon2D<T>::det(qs[k - 1] - qs[k - 2], ps[i] - qs[k - 1]) <= 0) k--; qs[k++] = ps[i]; } // up for (int i = vertex_num - 2, t = k; i >= 0; i--) { while (k > t && Polygon2D<T>::det(qs[k - 1] - qs[k - 2], ps[i] - qs[k - 1]) <= 0) k--; qs[k++] = ps[i]; } qs.resize(k - 1); return qs; } // Copy end const double PI = 3.14159265358979323846264338327950288; int main() { // This sample is AtCoder Grand Contest 21 B cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<Polygon2D<double>> ps(N); double x, y; for (int i = 0; i < N; ++i) { cin >> x >> y; ps[i] = Polygon2D<double>(x, y, i); } if (N == 2) { cout << fixed << setprecision(7); cout << 0.5 << endl; cout << 0.5 << endl; return 0; } vector<Polygon2D<double> > qs = convex_hull(ps, N); qs.push_back(qs[0]); qs.push_back(qs[1]); vector<double> ans(N, 0.0); for (int i = 0; i < (int)qs.size() - 2; i++) { Polygon2D<double> pr = qs[i] - qs[i + 1], pq = qs[i + 2] - qs[i + 1]; double len_pr = Polygon2D<double>::pow(pr); double len_pq = Polygon2D<double>::pow(pq); ans[qs[i + 1].getIdx()] = (PI - acos(Polygon2D<double>::dot(pr, pq) / sqrt(len_pr * len_pq))) / (2 * PI); } cout << fixed << setprecision(7); for (int i = 0; i < N; i++) { cout << ans[i] << endl; } return 0; }
0
#include <iostream> #include <limits.h> using namespace std; int m; int dijkstra( const int data[101][101], int start, int end ) { int i,j,next,min; bool visited[101]; int distance[101]; for( i = 1;i <= 100;i++ ){ visited[i] = false; distance[i] = INT_MAX; } distance[start] = 0; next = start; do{ i = next; visited[i] = true; min = INT_MAX; for(j = 1;j <= m;j++){ if(visited[j]) continue; if(data[i][j] < INT_MAX && distance[i] + data[i][j] < distance[j]) { distance[j] = distance[i] + data[i][j]; } if( distance[j] < min ){ min = distance[j]; next = j; } } } while( min < INT_MAX ); return distance[end]; } int main(int argc, char const* argv[]) { int n,weight[101][101][2]; while( cin >> n >> m && n != 0 && m != 0 ){ int a,b,c,d; for( int i = 0;i < 101;i++ ){ for( int j = 0;j < 101;j++ ){ weight[i][j][0] = INT_MAX; weight[i][j][1] = INT_MAX; } } for( int i = 0;i < n;i++ ){ cin >> a >> b >> c >> d; weight[a][b][0] = c; weight[b][a][0] = c; weight[a][b][1] = d; weight[b][a][1] = d; } cin >> n; for( int i = 0;i < n;i++ ){ int data[101][101]; int p,q,r; cin >> p >> q >> r; for( int j = 1;j < 101;j++ ){ for( int k = 1;k <101;k++ ) data[j][k] = weight[j][k][r]; } cout << dijkstra( data, p, q ) << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s)) #define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1)) #define rep(i,n) iota(i,(n),0,1) #define INF (1e9) #define EPS (1e-9) #define cons(a,b) (make_pair(a,b)) #define car(a) (a.first) #define cdr(a) (a.second) #define cadr(a) (car(cdr(a))) #define cddr(a) (cdr(cdr(a))) #define all(a) a.begin(), a.end() #define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl; typedef long long INTEGER; typedef double FLOAT; template<class S, class T> ostream& operator<<(ostream& os, pair<S,T> p) { os << '(' << car(p) << ", " << cdr(p) << ')'; return os; } template<class T> ostream& operator<<(ostream& os, vector<T> v) { os << v[0]; for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i]; return os; } const int MM = 100; int cost[MM][MM]; int toki[MM][MM]; int main() { entry:; int n, m; cin >> m >> n; if (n + m == 0) return 0; rep (i, n) { rep (j, n) { cost[i][j] = INF; toki[i][j] = INF; } cost[i][i] = 0; toki[i][i] = 0; } rep (i, m) { int a, b, c, t; cin >> a >> b >> c >> t; --a; --b; cost[a][b] = cost[b][a] = c; toki[a][b] = toki[b][a] = t; } rep (k, n) { rep (i, n) { rep (j, n) { cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]); toki[i][j] = min(toki[i][j], toki[i][k] + toki[k][j]); } } } //rep (i,n) { rep(j,n) { cout << cost[i][j] << ' '; } cout << endl; } int k; cin >> k; rep (i, k) { int a, b, t; cin >> a >> b >> t; --a; --b; if (t) { cout << toki[a][b] << endl; } else { cout << cost[a][b] << endl; } } goto entry; return 0; }
1
#include<bits/stdc++.h> #define ll long long using namespace std; int main() { ll n,q,m=0; cin>>n>>q; vector<ll> a(n+1); string s; cin>>s; for(int i=1;i<n;i++) { if(s[i-1]=='A'&& s[i]=='C') { a[i]=1; } } for(int i=1;i<=n;i++) a[i]+=a[i-1]; while(q--) { int l,r; cin>>l>>r; if(r==l) cout<<0<<endl; else { r--; cout<<a[r]-a[l-1]<<endl; } } return 0; }
/* * @Author: RBQRBQ * @Date: 2020-04-05 15:08:15 * @LastEditors: RBQRBQ * @LastEditTime: 2020-04-05 19:16:50 */ #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; typedef pair<ll,ll> pii; namespace IO{ template<typename T>inline void read(T &x){ x=0;ll f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();} while(isdigit(ch)){x=x*10+ch-48;ch=getchar();} x=x*f; } } using namespace IO; vector<pii> pp; vector<pii> T; ll mxL,minR,mxR,minL; int main() { int N; cin>>N; mxL=mxR=-1; minL=minR=10000000000ll; int P,Q; for(int i=1;i<=N;i++) { ll x,y; read(x),read(y); y++; pp.push_back(make_pair(x,y)); if(x>mxL) { mxL=x; P=i; } if(minR>y) { minR=y; Q=i; } } ll ans1=0,ans2=0; minL=0; for(int i=1;i<=N;i++) { minL=max(minL,pp[i-1].second-pp[i-1].first); } ans1=max((minL),0ll)+max((minR-mxL),0ll); int ca=1; for(auto p:pp) { if(ca!=P&&ca!=Q) T.push_back(make_pair(max(p.second-mxL,0ll),max(minR-p.first,0ll))); ca++; } sort(T.begin(),T.end()); ll P1=pp[P-1].second-pp[P-1].first; ll Q1=pp[Q-1].second-pp[Q-1].first; ll x1=0,x2=Q1; // for(auto p:T) // { // cout<<p.first<<" "<<p.second<<endl; // } for(int i=0;i<T.size();i++) { x1=min(T[i].first,P1); ans2=max(ans2,x1+x2); x2=min(T[i].second,x2); } ans2=max(ans2,P1+x2); cout<<max(ans1,ans2); }
0
#include <iostream> int main() { int k[10] = {}, w[10] = {}; int swap; for (int i = 0; i < 10; i++) { std::cin >> w[i]; } for (int j = 0; j < 10; j++) { std::cin >> k[j]; } for (int n = 1; n < 10; n++) { for (int m = 0; m < 10; m++) { if (w[n] > w[m]) { swap = w[m]; w[m] = w[n]; w[n] = swap; } } } for (int n = 1; n < 10; n++) { for (int m = 0; m < 10; m++) { if (k[n] > k[m]) { swap = k[m]; k[m] = k[n]; k[n] = swap; } } } std::cout << w[0] + w[1] + w[2] << " " << k[0] + k[1] + k[2] << std::endl; return 0; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { vector<int> vec(4); int his, geo, ans; for (int i = 0; i < 4; i++) cin >> vec[i]; cin >> his >> geo; sort(vec.begin(), vec.end(), greater<int>()); ans = vec[0] + vec[1] + vec[2] + (his > geo ? his : geo); cout << ans << endl; return 0; }
0
#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 <iostream> #include <string> #include <algorithm> #include <functional> #include <vector> #include <stack> #include <queue> #include <deque> #include <set> #include <map> #include <cstdio> #include <cmath> #include <tuple> #include <iomanip> #include <numeric> #include <unordered_map> #include <sstream> #include<limits.h> #include<float.h> #include<list> #include <array> #include <complex> #include<stdio.h> #include<string.h> #include <bitset> // #include<assert.h> #include<random> using namespace std; #define int long long #define I32_MAX 2147483647 #define I64_MAX 9223372036854775807LL #define I64_MAX2 1223372036854775807LL #define INF I64_MAX2 #define MOD 1000000007 // #define MOD 998244353 #define MEM_SIZE 100010 #define DEBUG_OUT true #define ALL(x) (x).begin(), (x).end() template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";} template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;} template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } } template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);} template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}} template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } //https://www.youtube.com/watch?v=RDaGj_ztNz4&feature=youtu.be //-----CODE------// void solve(void) { int n; cin>>n; vector<int> a (n,0); for (int i = 0; i < n; i++) { cin>>a[i]; } vector<vector<int> > dp (n+1,vector<int>(4,-1*INF)); dp[0][0] = 0; int k = 1 +n%2; for (int i = 0; i < n; i++) { for (int j = 0; j < k+1; j++) { chmax(dp[i+1][j+1],dp[i][j]); int now = dp[i][j]; if((i+j)%2 == 0) now += a[i]; chmax(dp[i+1][j],now); } } cout<<dp[n][k]<<endl; return; } int32_t main(int32_t argc, const char *argv[]) { std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout << std::fixed; std::cout << std::setprecision(11); solve(); return 0; }
0
#include <stdio.h> #include <math.h> #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) vector<pair<long long, long long> > prime_factorize(long long N) { vector<pair<long long, long long> > res; for (long long i = 2; i * i <= N; ++i) { if (N % i != 0) { continue; } long long ex = 0; // 指数 // 割れるだけ割る while (N % i == 0) { ++ex; N /= i; } // 結果を push res.push_back({i, ex}); } // 残った数はそのまま push if (N != 1) { res.push_back({N, 1}); } else { res.push_back({1, 1}); } return res; } int main() { long long N, target = 1, ans = 1, num = 1000000007; cin >> N; vector<long long> ex(N+1, 0); //指数情報を格納していく for (int i = 1; i <= N; ++i) { const auto &res = prime_factorize(i); for (auto p : res) { ex[p.first] += p.second; } } for (long long i = 2; i <= N; ++i) { ans *= ex[i] + 1 ; ans %= num; } cout << ans << endl; return 0; }
// C - Factors of Factorial #include<bits/stdc++.h> #define fast ios::sync_with_stdio(false);cin.tie(NULL) using namespace std; #define int long long #define MOD 1000000007 typedef vector<int> vi; typedef pair<int,int> pi; #define inf 1e18 #define For(i,a,b) for (int i = a; i < b; i++) #define Rep(i,a,b) for (int i = a; i <= b; i++) #define ps(x,y) fixed << setprecision(y) << x #define pb push_back #define mp make_pair int sieve[1005]; vi primes; int32_t main() { fast; int n, ans = 1; cin >> n; for(int x = 2; x <= n; x++) { if(sieve[x]) continue; for(int u = 2*x; u <= n; u += x) { sieve[u] = x; } } Rep(i, 2, n) { int cnt = 0; if(sieve[i] == 0) { int exp = 1; while(pow(i, exp) <= n) { int x = pow(i, exp); cnt += (n/x); exp++; } ans *= (cnt+1); ans %= MOD; } } cout << ans; return 0; }
1
#include<iostream> using namespace std; int main(){ int a,b,c,sum,maxim; cin>>a>>b>>c; sum=a+b+c; maxim=max(a,b); maxim=max(maxim,c); cout<<sum-maxim; }
#include <bits/stdc++.h> using namespace std; signed main() { int a[3]; for ( int i = 0; i < 3; i++ ) { cin >> a[i]; } sort(a, a+3); cout << a[0] + a[1] << endl; return (0); }
1
#include <bits/stdc++.h> using namespace std; using Graph = vector<vector<int>>; typedef long long ll; typedef pair<ll,ll> P; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define EFOR(i,a,b) for(int i=(a);i<=(b);++i) #define REP(i, n) FOR(i,0,n) #define IINF 1e9 int dx[4] = {0,1,0,-1}; int dy[4] = {1,0,-1,0}; // memo:BFS int main(void){ int h,w,ans = 0; cin >> h >> w; vector<vector<char>> s(h,vector<char>(w)); vector<vector<int>> dist(h,vector<int>(w,-2)); queue<P> q; int c_hash = 0; REP(i,h)REP(j,w){ cin >> s[i][j]; if(s[i][j] == '#') dist[i][j] = -1,c_hash++; } q.push(P(0,0)); dist[0][0] = 0; while(!q.empty()){ P v = q.front(); q.pop(); REP(i,4){ int vx = v.first + dx[i]; int vy = v.second + dy[i]; if(vx < 0 || vx >= h || vy < 0 || vy >= w) continue; if(dist[vx][vy] == -2){ dist[vx][vy] = dist[v.first][v.second] + 1; q.push(P(vx,vy)); } } } if(dist[h-1][w-1] > 0 ) ans = h*w - c_hash - dist[h-1][w-1] - 1; else ans = -1; cout << ans << endl; return 0; }
#include <iostream> #include <cstdio> #include <algorithm> #include <cstdlib> #include <cstring> #include <cmath> #include <vector> #include <queue> using namespace std; #define FOR(i,a,b) for (ll i = (a); i < (b); i++) #define REP(i,n) FOR(i,0,n) typedef long long ll; int a[1000]; int b[1000]; int c[1000]; int main(){ int n, m; cin >> n >> m; REP(i,n){ scanf("%d", &a[i]); } REP(i,m){ scanf("%d", &b[i]); } REP(i,m){ REP(j,n){ if (a[j] <= b[i]){ c[j]++; break; } } } int ma = 0; int ans; REP(i,n){ if (c[i] > ma){ ma = c[i]; ans = i+1; } } cout << ans << endl; return 0; }
0
#include<bits/stdc++.h> using namespace std; int main(){ int m, n; cin >> m >> n; int aux = 1; int res = 0; while(true){ if(aux >= n){break;} --aux; aux += m; res++; } cout << res <<"\n"; return 0; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <queue> #include <cmath> #include <climits> #include <iomanip> #include <set> #include <map> using namespace std; typedef long long ll; int main(){ int k,t; cin >> k >> t; vector<int> n(t); for(int i = 0;i < t;i++)cin >> n[i]; sort(n.begin(),n.end()); cout << max(0,n[t - 1] - (k - n[t - 1]) - 1) << endl; }
0
#include<bits/stdc++.h> #define For(i,x,y) for (register int i=(x);i<=(y);i++) #define FOR(i,x,y) for (register int i=(x);i<(y);i++) #define Dow(i,x,y) for (register int i=(x);i>=(y);i--) #define Debug(v) for (auto i:v) printf("%lld ",i);puts("") #define mp make_pair #define fi first #define se second #define pb push_back #define ep emplace_back #define siz(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() #define fil(a,b) memset((a),(b),sizeof(a)) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pa; typedef pair<ll,ll> PA; typedef vector<int> poly; inline ll read(){ ll x=0,f=1;char c=getchar(); while ((c<'0'||c>'9')&&(c!='-')) c=getchar(); if (c=='-') f=-1,c=getchar(); while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar(); return x*f; } const int N = 2e5+10; int n; inline PA Get(int d,ll c){ if (c==1) return {d,0}; PA tmp=Get(d,c/2); tmp.se=(tmp.se*2+1+(tmp.fi*2>=10)); if (tmp.fi*2>=10) tmp.fi=(tmp.fi*2)/10+(tmp.fi*2)%10; else tmp.fi*=2; if (c&1){ tmp.se=tmp.se+1+(tmp.fi+d>=10); tmp.fi=(tmp.fi+d)/10+(tmp.fi+d)%10; } return tmp; } int main(){ n=read(); ll x=0,ans=0; For(i,1,n){ ll d=read(),c=read(); PA tmp=Get(d,c); ans+=tmp.se; if (i!=1) ans++; ans+=(x+tmp.fi>=10); x=(x+tmp.fi)/10+(x+tmp.fi)%10; //printf(" %lld %lld\n",x,ans); } printf("%lld\n",ans); }
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #include <bits/stdc++.h> using namespace std; template<class t> inline t read(t &x){ char c=getchar();bool f=0;x=0; while(!isdigit(c)) f|=c=='-',c=getchar(); while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar(); if(f) x=-x;return x; } template<class t,class ...A> inline void read(t &x,A &...a){ read(x);read(a...); } template<class t> inline void write(t x){ if(x<0) putchar('-'),write(-x); else{if(x>9) write(x/10);putchar('0'+x%10);} } const int mod=998244353,N=305; int nm,m,n,f[N][N][N],ans,sum[N],a[N]; char s[N]; signed main(){ scanf("%s",s+1);read(m); n=strlen(s+1);s[++n]='0'; for(int i=1;i<=n;i++){ if(s[i]=='0') nm++; else a[nm+1]++; } for(int i=1;i<=nm;i++) sum[i]=sum[i-1]+a[i]; m=min(m,sum[nm]); f[0][0][0]=1; for(int i=1;i<=nm;i++) for(int j=sum[i];j<=sum[nm];j++){ int lim=min(j,sum[nm]-sum[i-1]); for(int k=0;k<=m;k++) for(int bi=0;bi<=lim;bi++) if(max(0,bi-a[i])<=k) f[i][j][k]=(f[i][j][k]+f[i-1][j-bi][k-max(0,bi-a[i])])%mod; } for(int i=0;i<=m;i++) ans=(ans+f[nm][sum[nm]][i])%mod; write(ans); }
0
#include<iostream> #include<sstream> #include<algorithm> #include<climits> #include<cmath> #include<cstdio> #include<cstdlib> #include<ctime> #include<cfloat> #include<functional> #include<map> #include<string> #include<cstring> #include<vector> #include<queue> #include<stack> #include<deque> #include<set> #include<bitset> #include<list> #include<numeric> #include<complex> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> i_i; typedef pair<long long, int> ll_i; typedef pair<double, int> d_i; typedef pair<long long, long long> ll_ll; typedef pair<double, double> d_d; typedef vector<int> Vint; #define PI 3.141592653589793238462643383279 #define mod 1000000007LL #define rep(i, n) for(i = 0;i < n;++i) #define rep1(i, n) for(i = 1;i < n;++i) #define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j) #define per(i, n) for(i = n - 1;i > -1;--i) #define int(x) int x; scanf("%d",&x) #define int2(x, y) int x, y; scanf("%d%d",&x, &y) #define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z) #define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z) #define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z) #define scn(n, a) rep(i, n)cin >> a[i] #define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i] #define pri(x) cout << x << "\n" #define pri2(x, y) cout << x << " " << y << "\n" #define pri3(x, y, z) cout << x << " " << y << " " << z << "\n" #define pb push_back #define mp make_pair #define all(a) (a).begin(),(a).end() #define endl "\n" #define kabe puts("---------------------------") #define kara puts("") #define debug(x) cout << " --- " << x << "\n" #define debug2(x, y) cout << " --- " << x << " " << y << "\n" #define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n" #define X first #define Y second #define eps 0.0001 #define prid(x) printf("%.15lf\n", x) signed main(void){ int i, j, k; for(int testcase = 0;testcase >= 0;testcase++){ int2(n, m); int a[n], cnt[n]; scn(n, a); rep(i, n)cnt[i] = 0; rep(i, m){ int(b); rep(j, n)if(b >= a[j]){ cnt[j]++; break; } } int ma = 0; rep1(i, n)if(cnt[ma] < cnt[i])ma = i; pri(ma + 1); /*/ //*/ break; } return 0; }
#include<iostream> using namespace std; int main(void) { int n,m,mo[1001],bo[1001],ans[1001],A=0,i2; cin>>n>>m; for(int i=0;i<n;i++){ ans[i]=0; } for(int i=0;i<n;i++){ cin>>mo[i]; } for(int i=0;i<m;i++){ cin>>bo[i]; } for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ if(mo[j]<=bo[i]){ i2=j; break; } } ans[i2]+=1; } for(int i=0;i<n;i++){ if(A<ans[i]){ A=ans[i]; i2=i; } } cout<<i2+1<<"\n"; }
1
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) #define all(v) v.begin(),v.end() #define len(x) (ll)(x).length() using namespace std; typedef long long ll; typedef pair<int,int> P; const int INF=1e9; const int di[] = {-1,0,1,0}; const int dj[] = {0,-1,0,1}; int main(){ double n; cin>>n; vector<double> x(n),y(n); rep(i,n) cin>>x[i]>>y[i]; vector<int> t(n); rep(i,n) t[i]=i; double sum=0; int cnt=0; auto dis= [&](int i,int j){ double dx=x[i]-x[j]; double dy=y[i]-y[j]; return sqrt(dx*dx+dy*dy); }; do{ for(int i=1;i<n;i++){ sum+=dis(t[i],t[i-1]); } cnt++; }while(next_permutation(all(t))); printf("%.10f\n",sum/cnt); }
//最少全域木 #include<iostream> #include<vector> #include<algorithm> using namespace std; int G[103][103]; int V; int NG[103][103];//新しくできるほう int used[103]; int main(){ int ans=0; cin>>V; for(int i=0;i<V;i++){ for(int j=0;j<V;j++){ cin>>G[i][j]; } } for(int i=0;i<103;i++)for(int j=0;j<103;j++)NG[i][j]=-1; used[0]=1; for(int i=0;i<V;i++){ int u=-1,a,b; for(int j=0;j<V;j++){ if(used[j]==0)u=i; } if(u==-1)break; int now=99999999; for(int j=0;j<V;j++){ for(int k=0;k<V;k++){ if(now>G[j][k]&&G[j][k]!=-1&&used[j]==1&&used[k]==0){ now=G[j][k]; a=j,b=k; } } } ans+=G[a][b]; used[b]=1; NG[a][b]=G[a][b]; } cout<<ans<<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 n; bool trust(int flag, int index) { bool trust = (flag >> index) & 1; return trust; } int count (int flag) { int dst = 0; rep(i, n) if (trust(flag, i)) dst++; return dst; } int main() { cin >> n; vector<vector<P>> evidence(n); rep(i, n) { int a; cin >> a; evidence.at(i).resize(a); rep(j, a) { cin >> evidence.at(i).at(j).first >> evidence.at(i).at(j).second; evidence.at(i).at(j).first--; } } int ans = 0; for (int flag = 0; flag < (1<<n); flag++) { bool ok = true; rep(i, n) { if (trust(flag, i)) { for (P p : evidence.at(i)) { if (trust(flag, p.first) ^ (p.second == 1)) { ok = false; break; } } } } if (ok) ans = max(ans, count(flag)); } cout << ans << endl; return 0; }
#include<iostream> using namespace std; int main(){ int n; string A,B,C; cin>>n; int count=0; cin>>A>>B>>C; for(int i=0;i<n;i++){ if(A[i]==B[i]){ if(B[i]!=C[i]) count++; } else if(B[i]==C[i]){ count++; } else if(A[i]==C[i]){ count++; } else{ count+=2; } } cout<<count; }
0
#include <bits/stdc++.h> #define ll long long #define pii pair<int,int> using namespace std; const ll MMM = -1e18; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; int a[n]; for (int i=0; i<n; i++) cin >> a[i]; int m = n/2; if (n&1) { ll ans = MMM; vector<ll> suff(m+1), pref(m+1), best_suff(m+1); // both end case for (int i=0; i<m; i++) { pref[i+1] = pref[i] + a[2*i]; } for (int i=m-1; i>=0; i--) { suff[i] = suff[i+1] + a[2*i+2]; } // single 3-jump for (int i=0; i<=m; i++) { ans = max(ans, pref[i] + suff[i]); } // double 2-jump for (int i=m-1; i>=0; i--) { // best_suff[i] = max(best_suff[i+1] + a[i*2+1], suff[i+1] + a[i*2+1]); best_suff[i] = max(best_suff[i+1], suff[i+1]) + a[i*2+1]; } bool dbg = false; if (dbg) { cout << "PREF "; for (ll x : pref) cout << x << ' '; cout << '\n'; cout << "SUFF "; for (ll x : suff) cout << x << ' '; cout << '\n'; cout << "BEST "; for (ll x : best_suff) cout << x << ' '; cout << '\n'; } ll best_pref = 0; ans = max(ans, best_suff[0]); for (int i=0; i<m; i++) { best_pref = max(best_pref, pref[i]) + a[i*2+1]; ans = max(ans, best_pref + best_suff[i+1]); } // ans = max(ans, max(best_pref, pref[ // one end case // should have covered by double 2-jump // neither end case ll tmp = 0; for (int i=0, idx=1; i<m; i++, idx+=2) tmp += a[idx]; ans = max(ans, tmp); cout << ans; } else { vector<ll> suff(m+1); for (int i=m-1; i>=0; i--) { suff[i] = suff[i+1] + a[2*i+1]; } ll ans = suff[0]; ll pref = 0; for (int i=0; i<m; i++) { pref += a[i*2]; ans = max(ans, pref + suff[i+1]); } cout << ans; } }
#include <bits/stdc++.h> using namespace std; template <typename T> void print(T t) { cout<<t<<endl; } template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); } #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl '\n' #define int long long #define double long double int arr[200005]; int cache[200005][3]; int vis[200005][3]; int n; int dp(int pos,int skip) { if(skip>n%2+1) return -1e18; if(pos>=n) { if(!skip && n%2) return -1e18; return 0; } if(vis[pos][skip]) return cache[pos][skip]; vis[pos][skip]=1; int ans=max(dp(pos+1,skip+1),arr[pos]+dp(pos+2,skip)); cache[pos][skip]=ans; return ans; } int32_t main() { IOS; cin>>n; for(int i=0;i<n;i++) cin>>arr[i]; print(dp(0,0)); }
1
#define _CRT_SECURE_NO_WARNINGS #include<bits/stdc++.h> #include <unordered_map> //#include"testlib.h" #define endl "\n" #define all(v) v.begin(),v.end() #define allr(s) s.rbegin(),s.rend() #define RT(s) return cout<<s,0 #define sz(s) (int)(s.size()) #define PI acos(-1) #define EPS 1e-8 #define watch(x) cout << (#x)<<" = "<<x<<endl using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 }; int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 }; void file() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); #else //freopen("street.in", "r", stdin); //freopen("out.txt", "w", stdout); #endif } void fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); } #define x first #define y second #define r 0 #define l 1 #define u 2 #define d 3 const int N = 2e5 + 9; vi dia[N + N + 9][2][4]; vi arr[N][4]; int gt(char ch) { if (ch == 'R') return r; if (ch == 'L') return l; if (ch == 'U') return u; if (ch == 'D') return d; } int main() { file(); fast(); int n; cin >> n; for (int i = 0; i < n; i++) { char ch; int xx, yy; cin >> xx >> yy >> ch; int g = gt(ch); dia[yy - xx + N][l][g].push_back(yy); dia[yy + xx][r][g].push_back(yy); if (g == l || g == r) arr[yy][g].push_back(xx); else arr[xx][g].push_back(yy); } for (int i = 0; i < N + N; i++) for (int j = 0; j < 4; j++) sort(all(dia[i][l][j])), sort(all(dia[i][r][j])); for (int i = 0; i < N; i++) for (int j = 0; j < 4; j++) sort(all(arr[i][j])); int ans = INT_MAX; // on the same horizonatl for (int i = 0; i < N; i++) { for (auto& it : arr[i][r]) { auto bs = lower_bound(all(arr[i][l]), it); if (bs != arr[i][l].end()) ans = min(ans, (*bs - it) * 5); } } // on the same vertically for (int i = 0; i < N; i++) { for (auto& it : arr[i][u]) { auto bs = lower_bound(all(arr[i][d]), it); if (bs != arr[i][d].end()) ans = min(ans, (*bs - it) * 5); } } // from r or l to d for (int i = 0; i < N + N; i++) { for (auto& it : dia[i][l][r]) { auto bs = lower_bound(all(dia[i][l][d]), it); if (bs != dia[i][l][d].end()) ans = min(ans, (*bs - it) * 10); } for (auto& it : dia[i][r][l]) { auto bs = lower_bound(all(dia[i][r][d]), it); if (bs != dia[i][r][d].end()) ans = min(ans, (*bs - it) * 10); } } // from u to r or l for (int i = 0; i < N + N; i++) { for (auto& it : dia[i][l][u]) { auto bs = lower_bound(all(dia[i][l][l]), it); if (bs != dia[i][l][l].end()) ans = min(ans, (*bs - it) * 10); } for (auto& it : dia[i][r][u]) { auto bs = lower_bound(all(dia[i][r][r]), it); if (bs != dia[i][r][r].end()) ans = min(ans, (*bs - it) * 10); } } if (ans == INT_MAX) RT("SAFE\n"); cout << ans << endl; return 0; }
#include<cstring> #include<cstdio> #include<iostream> #include<algorithm> #include<vector> #include<cmath> #include<map> #include<set> #define l(x) (x<<1) #define r(x) ((x<<1)|1) #define IL inline #define reg register #define LL long long #define N 200010 #define INF 0x3f3f3f3f using namespace std; int n,i,j; int ans=INF; set <int> S[N*4]; struct Data{ int x,y; char c; }a[N]; IL int Abs(int x){return (x<0)?-x:x;} IL void Swap(int &a,int &b){a^=b^=a^=b;} IL int Min(int a,int b){return (a<b)?a:b;} IL int Max(int a,int b){return (a>b)?a:b;} IL int read(){ int p=0,f=1; char c=getchar(); while (c<48||c>57) {if (c=='-') f=-1; c=getchar();} while (c>=48&&c<=57) p=(p<<1)+(p<<3)+c-48,c=getchar(); return p*f; } int main(){ #ifdef __Marvolo freopen("zht.in","r",stdin); freopen("zht.out","w",stdout); #endif n=read(); for (i=1;i<=n;i++){ a[i].x=read(); a[i].y=read(); a[i].c=getchar(); } if (n==1){ puts("SAFE"); return 0; } for (i=1;i<=n;i++) if (a[i].c=='U') S[a[i].x+a[i].y].insert(a[i].x); for (i=1;i<=n;i++){ if (a[i].c=='R'){ if (!S[a[i].x+a[i].y].size()) continue; j=*(--S[a[i].x+a[i].y].end()); if (j<a[i].x) continue; j=*S[a[i].x+a[i].y].upper_bound(a[i].x); ans=Min(ans,j-a[i].x); } } for (i=0;i<4*N;i++) S[i].clear(); //U--R for (i=1;i<=n;i++) if (a[i].c=='D') S[a[i].x+a[i].y].insert(a[i].x); for (i=1;i<=n;i++){ if (a[i].c=='L'){ if (!S[a[i].x+a[i].y].size()) continue; j=*S[a[i].x+a[i].y].begin(); if (j>a[i].x) continue; j=*(--S[a[i].x+a[i].y].upper_bound(a[i].x)); ans=Min(ans,a[i].x-j); } } for (i=0;i<4*N;i++) S[i].clear(); //D--L for (i=1;i<=n;i++) if (a[i].c=='R') S[a[i].y-a[i].x+N].insert(a[i].x); for (i=1;i<=n;i++){ if (a[i].c=='D'){ if (!S[a[i].y-a[i].x+N].size()) continue; j=*S[a[i].y-a[i].x+N].begin(); if (j>a[i].x) continue; j=*(--S[a[i].y-a[i].x+N].upper_bound(a[i].x)); ans=Min(ans,a[i].x-j); } } for (i=0;i<4*N;i++) S[i].clear(); //D--R for (i=1;i<=n;i++) if (a[i].c=='L') S[a[i].y-a[i].x+N].insert(a[i].x); for (i=1;i<=n;i++){ if (a[i].c=='U'){ if (!S[a[i].y-a[i].x+N].size()) continue; j=*(--S[a[i].y-a[i].x+N].end()); if (j<a[i].x) continue; j=*S[a[i].y-a[i].x+N].upper_bound(a[i].x); ans=Min(ans,j-a[i].x); } } for (i=0;i<4*N;i++) S[i].clear(); //D--R if (ans!=INF) ans*=2; for (i=1;i<=n;i++) if (a[i].c=='R') S[a[i].y].insert(a[i].x); for (i=1;i<=n;i++){ if (a[i].c=='L'){ if (!S[a[i].y].size()) continue; j=*S[a[i].y].begin(); if (j>a[i].x) continue; j=*(--S[a[i].y].upper_bound(a[i].x)); ans=Min(ans,a[i].x-j); } } for (i=0;i<4*N;i++) S[i].clear(); //L--R for (i=1;i<=n;i++) if (a[i].c=='U') S[a[i].x].insert(a[i].y); for (i=1;i<=n;i++){ if (a[i].c=='D'){ if (!S[a[i].x].size()) continue; j=*S[a[i].x].begin(); if (j>a[i].y) continue; j=*(--S[a[i].x].upper_bound(a[i].y)); ans=Min(ans,a[i].y-j); } } for (i=0;i<4*N;i++) S[i].clear(); //U--D if (ans==INF) puts("SAFE"); else cout<<ans*5<<endl; return 0; }
1
#include<bits/stdc++.h> #define maxn 505050 using namespace std; typedef long long ll; struct edge{ ll x,y,z; }e[maxn*4]; ll ans,pre[maxn],fa[maxn],n,a[maxn],b[maxn],c[maxn],d,p,q; int l[maxn],r[maxn]; int ffind(int x){ if (pre[x]==x) return x; pre[x]=ffind(pre[x]); return pre[x]; } void union_(int u,int v){ pre[v]=u; b[u]=min(b[u],b[v]); c[u]=min(c[u],c[v]); } bool cmp(edge x,edge y){ return x.z<y.z; } ll cost(int u,int v){ return 1ll*abs(u-v)*d+a[u]+a[v]; } ll f[maxn],g[maxn]; int main(){ cin >> n >> d; int cnt=0; for (int i=1;i<=n;i++) cin >> a[i]; for (int i=1;i<=n;i++) fa[i]=pre[i]=i,b[i]=a[i]-d*i,c[i]=a[i]+d*i; int tot=n; while (tot>1){ int p=1; ll res=b[fa[1]]; for (int i=2;i<=tot;i++){ ll tmp=c[fa[i]]; f[i]=tmp+res,g[i]=p; if (b[fa[i]]<res) res=b[fa[i]],p=i; } int q=n; res=c[fa[tot]]; for (int i=tot-1;i;i--){ ll tmp=b[fa[i]]; if (i==1||tmp+res<f[i]) f[i]=tmp+res,g[i]=q; if (c[fa[i]]<res) res=c[fa[i]],q=i; } for (int i=1;i<=tot;i++){ int u=ffind(fa[i]),v=ffind(fa[g[i]]); if (u!=v) union_(u,v),ans+=f[i]; } tot=0; for (int i=1;i<=n;i++){ fa[++tot]=ffind(i); while (i<n&&ffind(i+1)==fa[tot]) i++; } } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; int main(){ int n,i,l=0; cin>>n; vector<int> a(n+2); for(i=1;i<=n;i++) cin>>a.at(i); for(i=0;i<n+1;i++) l+=abs(a.at(i+1)-a.at(i)); for(i=1;i<n+1;i++){ if((a.at(i+1)-a.at(i))*(a.at(i)-a.at(i-1))>=0) cout<<l<<endl; else cout<<l-2*min(abs(a.at(i+1)-a.at(i)),abs(a.at(i)-a.at(i-1)))<<endl; } }
0
#include<bits/stdc++.h> using namespace std; #define MAXN 400005 #define MOD 998244353 #define LL long long int LL ans,res,C[MAXN],fac[MAXN],revfac[MAXN]; int n,m,k; LL qpow(LL a,int b) { LL tmp=1; while(b) { if(b&1) tmp=tmp*a%MOD; a=a*a%MOD; b>>=1; } return tmp%MOD; } void facrev() { C[0]=1; C[1]=(n-1); fac[1]=1; fac[0]=1; revfac[0]=1; revfac[1]=1; for(int i=2;i<=n;i++) { fac[i]=fac[i-1]*i%MOD; C[i]=C[i-1]*(n-i)%MOD; } revfac[n]=qpow(fac[n],MOD-2); for(int i=n-1;i>=1;i--) { revfac[i]=revfac[i+1]*(i+1)%MOD; C[i]=C[i]*revfac[i]%MOD; } } int main() { scanf("%d%d%d",&n,&m,&k); facrev(); int p=n-k; res=m; for(int i=1;i<=p-1;i++) { res=res*(m-1)%MOD; } ans=res*C[p-1]%MOD; for(int j=p+1;j<=n;j++) { res=res*(m-1)%MOD; ans=(ans+res*C[j-1]%MOD)%MOD; } printf("%lld\n",ans); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) #define FOR(i, a, b) for (int i = a; i < b; ++i) #define ALL(vec) vec.begin(), vec.end() #define rALL(vec) vec.rbegin(), vec.rend() using namespace std; using ll = long long; // ------------------------------ int main() { int N; string s, t; cin >> N >> s >> t; int cnt = 0; rep(i, N) { string left = s.substr(N - i - 1, i + 1); string right = t.substr(0, i + 1); if (right == left) cnt = i + 1; } cout << 2*N - cnt << endl; return 0; }
0
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll h1,m1,h2,m2,k; cin>>h1>>m1>>h2>>m2>>k; ll t=((h2-h1)*60)-m1+m2; ll d=t-k; if(d<=0){ cout<<"0"<<"\n"; } else{ cout<<d<<"\n"; } return 0; }
#include<stdio.h> int main() { int h1,h2,m1,m2,k; scanf("%d%d%d%d%d",&h1,&m1,&h2,&m2,&k); m1+=60*h1; m2+=60*h2; printf("%d\n",m2-m1-k); return 0; }
1
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> // Acknowledgement: Special thanks to kyomukyomupurin, who developed this // template. template <class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '(' << p.first << ", " << p.second << ')'; } template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { int n = 0; for (auto e : vec) os << (n++ ? ", " : "{") << e; return os << (n ? "}" : "{}"); } template <class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { int n = 0; for (auto e : st) os << (n++ ? ", " : "{") << e; return os << (n ? "}" : "{}"); } template <class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { int n = 0; for (auto e : mp) os << (n++ ? ", " : "{") << e; return os << (n ? "}" : "{}"); } template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { for (T& e : vec) is >> e; return is; } #ifdef LOCAL #define debug(...) \ std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__) #else #define debug(...) #endif void debug_out() { std::cerr << '\n'; } template <class Head, class... Tail> void debug_out(Head&& head, Tail&&... tail) { std::cerr << head; if (sizeof...(Tail) != 0) std::cerr << ", "; debug_out(std::forward<Tail>(tail)...); } using namespace std; using int64 = long long; int main() { int H, W; cin >> H >> W; vector<vector<int>> a(H, vector<int>(W)); for (int i = 0; i < H; i++) { cin >> a[i]; } int n = 0; string ans = ""; vector<int> od_row_idx; for (int i = 0; i < H; i++) { vector<int> od_idx; for (int j = 0; j < W; j++) { if (a[i][j] % 2 == 1) { od_idx.push_back(j); } } debug(od_idx); if ((int)od_idx.size() == 0) continue; for (int j = 0; j < (int)od_idx.size() - 1; j += 2) { for (int k = od_idx[j]; k < od_idx[j + 1]; k++) { ans += to_string(i + 1) + ' ' + to_string(k + 1) + ' ' + to_string(i + 1) + ' ' + to_string(k + 2) + '\n'; n++; } } if ((int)od_idx.size() % 2 == 1) { for (int k = od_idx.back(); k < W - 1; k++) { ans += to_string(i + 1) + ' ' + to_string(k + 1) + ' ' + to_string(i + 1) + ' ' + to_string(k + 2) + '\n'; n++; } od_row_idx.push_back(i); } } if ((int)od_row_idx.size() > 1) { for (int j = 0; j < (int)od_row_idx.size() - 1; j += 2) { for (int k = od_row_idx[j]; k < od_row_idx[j + 1]; k++) { ans += to_string(k + 1) + ' ' + to_string(W) + ' ' + to_string(k + 2) + ' ' + to_string(W) + '\n'; n++; } } } cout << n << endl; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define endl "\n" using namespace std; using ll = long long; const ll MOD = 1000000007LL; // = 10^9 + 7 const double PI = 3.14159265358979; void solve() { int h, w; cin >> h >> w; vector< vector<int> > a( h, vector<int>(w) ); for(int i = 0; i < h; ++i) { for(int j = 0; j < w; ++j) { cin >> a[i][j]; } } vector<tuple<int, int, int, int>> ans; for(int i = 0; i < h; ++i) { for(int j = 0; j < w; ++j) { if(a[i][j] & 1) { if (j < w - 1) { a[i][j + 1]++; ans.emplace_back(make_tuple(i, j, i, j + 1)); } else if (i < h - 1) { a[i + 1][j]++; ans.emplace_back(make_tuple(i, j, i + 1, j)); } } } } cout << ans.size() << endl; for(const auto& t : ans) { int x, y, ax, ay; tie(x, y, ax, ay) = t; cout << x + 1 << " " << y + 1 << " " << ax + 1 << " " << ay + 1 << endl; } } int main() { fastio; solve(); return 0; }
1
#include<cstdio> #include<cstring> #include<stack> struct p{ int x; int y; }; using namespace std; int main(){ int w,h,sx,sy,gx,gy,n,c,d,x,y,i,j,k,o; int map[100][100]; int used[100][100]; int mx[4]={-1,0,1,0}; int my[4]={0,-1,0,1}; p v,u; stack<p> s; while(1){ scanf("%d %d",&w,&h); if(w==0&&h==0){ break; } memset(map,0,sizeof(map)); memset(used,0,sizeof(used)); scanf("%d %d",&sx,&sy); sx--; sy--; scanf("%d %d",&gx,&gy); gx--; gy--; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d %d %d %d",&c,&d,&x,&y); x--; y--; if(!d){ for(j=y;j<y+2;j++){ for(k=x;k<x+4;k++){ map[j][k]=c; } } } else{ for(j=y;j<y+4;j++){ for(k=x;k<x+2;k++){ map[j][k]=c; } } } } if(map[sy][sx]!=map[gy][gx]){ printf("NG\n"); continue; } v.x=sx; v.y=sy; s.push(v); o=0; while(!s.empty()){ v=s.top(); s.pop(); if(used[v.y][v.x]){ continue; } else{ used[v.y][v.x]=1; } if(v.x==gx&&v.y==gy){ o=1; while(!s.empty()){ s.pop(); } break; } for(i=0;i<4;i++){ u=v; u.x+=mx[i]; u.y+=my[i]; if(u.x>=0&&u.x<w&&u.y>=0&&u.y<h&&map[u.y][u.x]==map[sy][sx]){ s.push(u); } } } if(o){ printf("OK\n"); } else{ printf("NG\n"); } } return 0; }
#include <iostream> #include <string> using namespace std; string ans; int w,h,gx,gy; int map[110][110]; int dx_[4] = {0,1,0,-1}; int dy_[4] = {1,0,-1,0}; int dx[2][8] = { {0,1,2,3,0,1,2,3}, {0,1,0,1,0,1,0,1} }; int dy[2][8] = { {0,0,0,0,1,1,1,1}, {0,0,1,1,2,2,3,3}, }; void solve(int x,int y,int color){ if( ans == "OK" || color == 0 /*|| map[y][x] != color*/ ) return; //if( x<0 || x>w || y<0 || y>h ) return; for(int i=0 ; i<4 ; ++i ){ int mx = x + dx_[i]; int my = y + dy_[i]; if( mx<0 || mx>w || my<0 || my>h ) continue; //cout << "x:" << x << " y:" << y << endl; if( map[my][mx] == color ){ if( mx == gx && my == gy ){ ans = "OK"; }else{ map[my][mx] = 0; solve( mx , my , color ); } } } } void debug(){ char c[6] = {' ','#','$','*','+','@'}; cout << "w:" << w << " h:" << h << " map : " << endl; for(int y=0 ; y<h ; ++y ){ for(int x=0 ; x<w ; ++x ){ cout << c[ map[y][x] ]; } cout << endl; } } int main(){ int sx,sy,n; while( cin >> w >> h , w|h ){ ans = "NG"; for(int y=0 ; y<110 ; ++y ) for(int x=0 ; x<110 ; ++x ) map[y][x] = 0; cin >> sx >> sy >> gx >> gy >> n ; for(int i=0 ; i<n ; ++i ){ int c,d,x,y; cin >> c >> d >> x >> y; for(int j=0 ; j<8 ; j++){ int mx = x + dx[d][j]; int my = y + dy[d][j]; map[my][mx] = c; } } //debug(); //map[sy][sx] = 0; solve( sx , sy , map[sy][sx] ); //cout << "sx:" << sx << " sy:" << sy << endl; cout << ans << endl; } }
1
#include <iostream> using namespace std; //const double PI = acos(-1); using ll = long long; using ull = unsigned long long; const int inf = 2e9; const ll INF = 2e18; const ll MOD = 1e9+7; #define REP(i,n) for (int i = 0; i < (n); i++) #define sz(s) (s).size() #define pb push_back #define fi first #define se second ll n,a,b,c,d; ll dp[1010][1010]; ll K[1010]; ll cc[1010][1010]; ll inv[1010]; ll mul(ll _a, ll _b) { if (_b == 0) return 1LL; if (_b == 1) return _a; ll ans = mul(_a, _b/2); ans *= ans; ans %= MOD; if (_b&1) ans *= _a; return ans % MOD; } ll C(ll _n, ll _k) { if (cc[_n][_k] != 0LL) return cc[_n][_k]; if (_n == _k) return cc[_n][_k] = 1; return cc[_n][_k] = (K[_n] * ((inv[_k] * inv[_n-_k]) % MOD)) % MOD; } ll get(ll groups, ll mem, ll from) { ll ans = 1; REP(i,groups) { ans *= C(from, mem); ans %= MOD; from -= mem; } return (ans * inv[groups]) % MOD; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cin >> n >> a >> b >> c >> d; dp[0][0] = 1; K[1] = 1; inv[1] = 1; for (ll i = 2; i <= n; i++) { K[i] = K[i-1]*i; K[i] %= MOD; inv[i] = mul(K[i], MOD-2); } for (ll i = 1; i <= b; i++) { if (i < a) { dp[i][0] += dp[i-1][0]; dp[i][0] %= MOD; continue; } REP(j,n+1) { dp[i][j] += dp[i-1][j]; dp[i][j] %= MOD; ll k = c; while (k <= d && j + k * i <= n) { dp[i][j+k*i] += dp[i-1][j] * get(k, i, n-j); dp[i][j+k*i] %= MOD; k++; } } } cout << dp[b][n] << endl; return 0; }
#include <bits/stdc++.h> #include <string> #include <cmath> #include <sstream> //#include <unordered_map> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define FORD(i, a, b) for(int i = (a-1); i >= (b); i--) #define pb(a) push_back(a) #define mp(a,b) make_pair(a,b) typedef long long int ll; using namespace std; ll mod=1000000007; //ll mod=67280421310721; //ll mod=998244353; ll INF=1e18; ll po(ll a,ll b) { ll re=1; while(b) { if(b%2==1) { re=(re*a); re%=mod; } a=(a*a); a%=mod; b>>=1; } return re; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int test=1; // cin>>test; while(test--) { int n,m; cin>>n>>m; ll x[n],y[m],l=0,b=0; cin>>x[0]; FOR(i,1,n) { cin>>x[i]; l=(l+(i*(((n-i)*(x[i]-x[i-1]))%mod)))%mod; } cin>>y[0]; FOR(i,1,m) { cin>>y[i]; b=(b+(i*(((m-i)*(y[i]-y[i-1]))%mod)))%mod; } cout<<(l*b)%mod; } return 0; }
0
#include <bitset> #include <tuple> #include <string> #include <array> #include <deque> #include <queue> #include <stack> #include <vector> #include <map> #include <set> #include <algorithm> #include <cstdio> #include <cmath> #ifdef LOCAL #include <iostream> #endif using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define all(v) v.begin(), v.end() typedef long long ll; #ifdef LOCAL #define debug_echo(e) cout << "L" << __LINE__ << ": " << e << "\n" #define debug_repr(e) cout << "L" << __LINE__ << ": " << #e << " -> " << e << "\n" #else #define debug_echo(e) #define debug_repr(e) #endif #define defread(T, fmt) \ inline T read_ ## T() { \ T result; \ scanf(fmt, &result); \ return result; \ } defread(int, "%d") defread(ll, "%lld") defread(float, "%f") defread(double, "%lf") int gcd(int m, int n) { if ((0 == m) || (0 == n)) return 0; while (m != n) { if (m > n) m -= n; else n -= m; } return m; } int lcm(int m, int n) { if ((0 == m) || (0 == n)) return 0; return (m / gcd(m, n)) * n; } int main() { vector<int> a(4); vector<int> b(2); a[0] = read_int(); a[1] = read_int(); a[2] = read_int(); a[3] = read_int(); b[0] = read_int(); b[1] = read_int(); sort(all(a)); sort(all(b)); printf("%d\n", a[1] + a[2] + a[3] + b[1]); }
#include<bits/stdc++.h> using namespace std; int main(){ int s=0; int a=0,b=INT_MAX; int c; for(int d=0;d<4;d++){ scanf("%d",&c); a+=c; b=min(b,c); } a-=b; b=INT_MAX; for(int d=0;d<2;d++){ scanf("%d",&c); a+=c; b=min(b,c); } printf("%d\n",a-b); }
1
#include<stdio.h> int main() { int n, A[10001]; scanf("%d", &n); int i; for (i = 0; i <= n - 1; i++) { scanf("%d ", &A[i]); } long int min = 1000001, max = -1000001, total = 0; for (i = 0; i <= n - 1; i++) { if (min > A[i]) min = A[i]; if (max < A[i]) max = A[i]; total = total + A[i]; } printf("%ld %ld %ld\n", min, max, total); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; // -------------------------------------------------------- #define FOR(i,l,r) for (int i = (l); i < (r); ++i) #define REP(i,n) FOR(i,0,n) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) #define MIN(c) *min_element(ALL(c)) #define MAX(c) *max_element(ALL(c)) #define SUM(c) accumulate(ALL(c), 0) #define SUMLL(c) accumulate(ALL(c), 0LL) #define SZ(c) ((int)(c).size()) #define debug(x) cerr << #x << " = " << (x) << '\n'; using P = pair<int,int>; using VP = vector<P>; using VVP = vector<VP>; using VS = vector<string>; using VI = vector<int>; using VVI = vector<VI>; using VLL = vector<ll>; using VVLL = vector<VLL>; using VB = vector<bool>; using VVB = vector<VB>; using VD = vector<double>; using VVD = vector<VD>; const double EPS = 1e-10; const double PI = acos(-1.0); const ll MOD = 1000000007; // const ll MOD = 998244353; const int INF = 1 << 30; // const ll INF = 1LL << 62; // -------------------------------------------------------- int binary_search_A(vector<int> &a, int key) { // Meguru type binary search int ok = -1; int ng = a.size(); auto is_ok = [&] (int idx) { if (a[idx] < key) { return true; } else { return false; } }; int mid; while (abs(ok - ng) > 1) { mid = (ok + ng) / 2; if (is_ok(mid)) { ok = mid; } else { ng = mid; } } return ok; } int binary_search_C(vector<int> &a, int key) { // Meguru type binary search int ng = -1; int ok = a.size(); auto is_ok = [&] (int idx) { if (key < a[idx]) { return true; } else { return false; } }; int mid; while (abs(ok - ng) > 1) { mid = (ok + ng) / 2; if (is_ok(mid)) { ok = mid; } else { ng = mid; } } return ok; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); int N; cin >> N; VI A(N); REP(i,N) cin >> A[i]; VI B(N); REP(i,N) cin >> B[i]; VI C(N); REP(i,N) cin >> C[i]; SORT(A); SORT(B); SORT(C); ll ans = 0; for (auto b : B) { int ia = binary_search_A(A, b); int ic = binary_search_C(C, b); ans += (ll)(ia + 1) * (N - ic); } cout << ans << '\n'; return 0; }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) (x).begin(),(x).end() const int mod=998244353,MAX=103,INF=1<<30; ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b); } int N; bool DFS(vector<ll> A){ vector<ll> left(N+2),right(N+2); ll sum=0; for(int i=0;i<N;i++){ sum+=A[i]; } if((sum-N)%2){ return 1; } for(int i=1;i<=N;i++){ left[i]=gcd(left[i-1],A[i-1]); } for(int i=N;i>=1;i--){ right[i]=gcd(right[i+1],A[i-1]); } bool res=false; for(int i=1;i<=N;i++){ if(A[i-1]==1) continue; ll g=gcd(gcd(left[i-1],A[i-1]-1),right[i+1]); if(g==1) continue; if(((sum-1)/g-N)%2==0){ vector<ll> to(N); to=A; for(int j=0;j<N;j++){ if(j==i-1) to[j]--; to[j]/=g; } res|=!DFS(to); } } return res; } int main(){ std::ifstream in("text.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); cin>>N; vector<ll> A(N); for(int i=0;i<N;i++){ cin>>A[i]; } if(DFS(A)) cout<<"First"<<endl; else cout<<"Second"<<endl; }
#include<bits/stdc++.h> using namespace std; const int N = 1000 * 100 + 10; int n, a[N], tt = 0; string ans[2] = {"First\n", "Second\n"}; void solve() { long long sum = 0; bool one = false; int cnt[2] = {0, 0}; for (int i = 0; i < n; i++) { one |= a[i] == 1; sum += a[i] - 1; cnt[a[i] & 1]++; } if (one) { cout << ans[(sum + 1 + tt) & 1]; exit(0); } if (n == 1) { cout << ans[(sum + 1 + tt) & 1]; exit(0); } if (cnt[0] & 1) { cout << ans[tt & 1]; exit(0); } if (cnt[1] >= 2) { cout << ans[(1 + tt) & 1]; exit(0); } for (int i = 0; i < n; i++) if (a[i] & 1) { a[i]--; break; } long long g = a[0]; for (int i = 1; i < n; i++) g = __gcd(1LL * a[i], g); for (int i = 0; i < n; i++) a[i] /= g; tt++; solve(); } int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; solve(); return 0; }
1
#include <bits/stdc++.h> #include <cmath> const double PI = 3.14159265358979323846; using namespace std; typedef long long ll; const double EPS = 1e-9; #define rep(i, n) for (int i = 0; i < (n); ++i) //#define rep(i, n) for (ll i = 0; i < (n); ++i) //typedef pair<ll, ll> P; typedef pair<ll, ll> P; const ll INF = 10e17; #define cmin(x, y) x = min(x, y) #define cmax(x, y) x = max(x, y) #define ret() return 0; std::istream &operator>>(std::istream &in, set<int> &o) { ll a; in >> a; o.insert(a); return in; } std::istream &operator>>(std::istream &in, queue<int> &o) { ll a; in >> a; o.push(a); return in; } bool contain(set<int> &s, int a) { return s.find(a) != s.end(); } //ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt"); //ofstream outfile("log.txt"); //outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl; // std::cout << std::bitset<8>(9); //const ll mod = 1e10; typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK; #include <iostream> #include <vector> using namespace std; const int mod = 1000000007; class UnionFind { public: // 親の番号を格納する。親だった場合-size vector<int> parents; UnionFind(int n) { parents = vector<int>(n, -1); } // aがどのグループに属しているか int root(int a) { if (parents[a] < 0) { return a; } return parents[a] = root(parents[a]); } int size(int a) { return -parents[root(a)]; } // aとbをくっつける bool connect(int a, int b) { int ra = root(a); int rb = root(b); if (ra == rb) { return false; } // 大きいほうにA if (size(ra) < size(rb)) { swap(ra, rb); } parents[ra] += parents[rb]; parents[rb] = ra; return true; } bool is_union(int a, int b) { int ra = root(a); int rb = root(b); return ra == rb; } }; int main() { int h, w; cin >> h >> w; vector<vector<char>> grid(h, vector<char>(w)); rep(y, h) rep(x, w) cin >> grid[y][x]; auto to_id = [&](int y, int x) { return y * w + x; }; UnionFind uf(h * w); struct Direction { int x, y; }; vector<Direction> directions = { {0, 1}, {1, 0}, {0, -1}, {-1, 0}, }; rep(y, h) { rep(x, w) { for (Direction d : directions) { int ny = y + d.y; int nx = x + d.x; if (ny < 0 || h <= ny || nx < 0 || w <= nx) continue; if (grid[y][x] != grid[ny][nx]) uf.connect(to_id(y, x), to_id(ny, nx)); } } } UnionFind uf2(h * w); rep(y, h) { rep(x, w) { if (grid[y][x] != '#') continue; for (Direction d : directions) { int ny = y + d.y; int nx = x + d.x; if (ny < 0 || h <= ny || nx < 0 || w <= nx) continue; if (grid[ny][nx] != '.')continue; for (Direction e : directions) { int nny = ny + e.y; int nnx = nx + e.x; if (nny < 0 || h <= nny || nnx < 0 || w <= nnx) continue; if (grid[nny][nnx] != '#')continue; uf2.connect(to_id(y, x), to_id(nny, nnx)); } } } } ll ans = 0; rep(y, h) { rep(x, w) { if (grid[y][x] != '#') continue; ll now = uf.size(to_id(y, x)) - uf2.size(to_id(y, x)); // cout << uf.size(to_id(y, x)) << ' ' << uf2.size(to_id(y, x)) << ' ' << now << endl; ans += now; } } cout << ans << endl; }
#include <iostream> using namespace std; int main() { int n, m; int a[1010][2] = {0}; int b; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i][0]; } for (int i = 0; i < m; i++) { cin >> b; for (int j = 0; j < n; j++) { if (a[j][0] <= b) { a[j][1]++; break; } } } int max[2] = {0}; for (int i = 0; i < n; i++) { if (max[1] < a[i][1]) { max[1] = a[i][1]; max[0] = i+1; } } cout << max[0] << endl; return 0; }
0