A - Prefix and Suffix
A - Prefix and Suffix
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); ++i) #define repx(i,x,n) for(int i=x; i<(n); ++i) #define fixed_setprecision(n) fixed << setprecision((n)) #define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC); #define pai 3.1415926535897932384 #define NUM_MAX 2e18 #define NUM_MIN -1e9 using namespace std; using ll = long long; using P = pair<int,int>; template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; } int main() { int N; string s, t; cin >> N >> s >> t; int copy=0, len=N; for(int i=0; i<N; i++){ int ok = 1; for(int j=0; j<N; j++){ if(i+j<N) if(s[i+j] != t[j]) ok = 0; } if(ok) len = min(len, i); } string ans = s.substr(0, len) + t; cout << ans.size() << endl; return 0; }
A - Sorted Arrays
A - Sorted Arrays
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); ++i) #define repx(i,x,n) for(int i=x; i<(n); ++i) #define fixed_setprecision(n) fixed << setprecision((n)) #define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC); #define pai 3.1415926535897932384 #define NUM_MAX 2e18 #define NUM_MIN -1e9 using namespace std; using ll = long long; using P = pair<int,int>; template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; } int main() { int N; cin >> N; int res=0; vector<int> A(N); for(auto &a:A) cin >> a; for(int i=0; i<N; i++){ while(i+1<N && A[i] == A[i+1]) i++; if(i+1<N && A[i] < A[i+1]) while(i+1<N && A[i] <= A[i+1]) i++; else if(i+1<N && A[i] > A[i+1]) while(i+1<N && A[i] >= A[i+1]) i++; res++; } cout << res << endl; return 0; }
C - Not so Diverse
C - Not so Diverse
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); ++i) #define repx(i,x,n) for(int i=x; i<(n); ++i) #define fixed_setprecision(n) fixed << setprecision((n)) #define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC); #define pai 3.1415926535897932384 #define NUM_MAX 2e18 #define NUM_MIN -1e9 using namespace std; using ll = long long; using P = pair<int,int>; template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; } int main() { int N, K; cin >> N >> K; map<int, int> mp; for(int i=0; i<N; i++){ int a; cin >> a; mp[a]++; } vector<int> A; for(auto &m:mp) A.push_back(m.second); sort(A.begin(), A.end()); int ans=0; int sum = mp.size(); for(int i=0; i<sum - K; i++){ ans += A[i]; } cout << ans << endl; return 0; }
A - A+...+B Problem
A - A+...+B Problem
N, A, B = list(map(int, input().split())) if N==1 and A != B: print(0) elif N==1 and A == B: print(1) elif A > B: print(0) else: num_min = (N-1)*A + B num_max = A + (N-1) * B print(num_max - num_min + 1)
B - RGB Boxes
B - RGB Boxes
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); ++i) #define repx(i,x,n) for(int i=x; i<(n); ++i) #define fixed_setprecision(n) fixed << setprecision((n)) #define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC); #define pai 3.1415926535897932384 #define NUM_MAX 2e18 #define NUM_MIN -1e9 using namespace std; using ll = long long; using P = pair<int,int>; template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; } int main() { int R, G, B, N; cin >> R >> G >> B >> N; int ans=0; for(int i=0; i<=N; i++){ for(int j=0; j<=N; j++){ int v = i*R + j*G; if(N>=v && (N - v) % B==0) ans++; } } cout << ans << endl; return 0; }
C - Write and Erase
C - Write and Erase
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); ++i) #define repx(i,x,n) for(int i=x; i<(n); ++i) #define fixed_setprecision(n) fixed << setprecision((n)) #define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC); #define pai 3.1415926535897932384 #define NUM_MAX 2e18 #define NUM_MIN -1e9 using namespace std; using ll = long long; using P = pair<int,int>; template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; } int main() { ll N; cin >> N; map<int, int> mp; for(int i=0; i<N; i++){ int a; cin >> a; if(mp[a]==0) mp[a]++; else mp[a]--; } ll ans = 0; for(auto m:mp){ if(m.second) ans++; } cout << ans << endl; return 0; }
C - Sentou
C - Sentou
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); ++i) #define repx(i,x,n) for(int i=x; i<(n); ++i) #define fixed_setprecision(n) fixed << setprecision((n)) #define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC); #define pai 3.1415926535897932384 #define NUM_MAX 2e18 #define NUM_MIN -1e9 using namespace std; using ll = long long; using P = pair<int,int>; template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; } int main() { ll N, T; cin >> N >> T; vector<ll> t(N); for(auto &tt:t) cin >> tt; ll time = 0; ll ans = 0; for(auto tt:t){ ans += min(tt - time, T); time = tt; } cout << ans + T << endl; return 0; }