diff --git a/README.md b/README.md index e7a4502..52d75b6 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # CPcode + You have read me +This is my competitive programming solutions repository. It is mostly no longer updated tho. + If one of my usaco or cses sols are missing or not working, I have almost certaintly solved it but didn't update my github. Send me a message on codeforces (SuperJ6) if you want me to update a particular problem. diff --git a/c++ sol/hackercup/2024/round1/.gitignore b/c++ sol/hackercup/2024/round1/.gitignore new file mode 100644 index 0000000..f83c766 --- /dev/null +++ b/c++ sol/hackercup/2024/round1/.gitignore @@ -0,0 +1,2 @@ +in.txt +out.txt diff --git a/c++ sol/hackercup/2024/round1/A/sol b/c++ sol/hackercup/2024/round1/A/sol new file mode 100755 index 0000000..934ef58 Binary files /dev/null and b/c++ sol/hackercup/2024/round1/A/sol differ diff --git a/c++ sol/hackercup/2024/round1/A/sol.cpp b/c++ sol/hackercup/2024/round1/A/sol.cpp new file mode 100644 index 0000000..110f8dc --- /dev/null +++ b/c++ sol/hackercup/2024/round1/A/sol.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include +using namespace std; +#define endl '\n' +#define ll long long +#define pi pair +#define f first +#define s second + +int n; + +void answer(){ + cin >> n; + + double min_v = 0, max_v = 1e9; + for(int i = 1; i <= n; i++){ + int min_t, max_t; + cin >> min_t >> max_t; + min_v = max(min_v, (double)i / max_t); + max_v = min(max_v, (double)i / min_t); + } + + if(min_v > max_v){ + cout << -1 << endl; + return; + } + + cout << min_v << endl; +} + +int main(){ + freopen("in.txt", "r", stdin); + freopen("out.txt", "w", stdout); + ios::sync_with_stdio(0); + cin.tie(0); + cout << fixed << setprecision(7); + + int t; + cin >> t; + + for(int i = 1; i <= t; i++){ + cout << "Case #" << i << ": "; + answer(); + } + + return 0; +} diff --git a/c++ sol/hackercup/2024/round1/A/subsonic_subway_input.zip b/c++ sol/hackercup/2024/round1/A/subsonic_subway_input.zip new file mode 100644 index 0000000..375606e Binary files /dev/null and b/c++ sol/hackercup/2024/round1/A/subsonic_subway_input.zip differ diff --git a/c++ sol/hackercup/2024/round1/B/prime_subtractorization_input.zip b/c++ sol/hackercup/2024/round1/B/prime_subtractorization_input.zip new file mode 100644 index 0000000..f28bd74 Binary files /dev/null and b/c++ sol/hackercup/2024/round1/B/prime_subtractorization_input.zip differ diff --git a/c++ sol/hackercup/2024/round1/B/sol b/c++ sol/hackercup/2024/round1/B/sol new file mode 100755 index 0000000..43f3946 Binary files /dev/null and b/c++ sol/hackercup/2024/round1/B/sol differ diff --git a/c++ sol/hackercup/2024/round1/B/sol.cpp b/c++ sol/hackercup/2024/round1/B/sol.cpp new file mode 100644 index 0000000..2041398 --- /dev/null +++ b/c++ sol/hackercup/2024/round1/B/sol.cpp @@ -0,0 +1,62 @@ +#include +#include +#include +#include +using namespace std; +#define endl '\n' +#define ll long long +#define pi pair +#define f first +#define s second + +const int m = 10000001; +int n; +int is_subpr[m], pref_subpr[m], lp[m]; +vector p; + +void precomp_primes(){ + for(int i = 2; i < m; i++){ + if(!lp[i]){ + lp[i] = i; + p.push_back(i); + } + for(int j = 0; j < p.size() && i * p[j] < m && p[j] <= lp[i]; j++){ + lp[i * p[j]] = p[j]; + } + } +} + +void precomp_subprimes(){ + for(int i = 2; i < m; i++){ + is_subpr[i] = (i == 2 || (lp[i] == i && lp[i + 2] == i + 2)) ? 1 : 0; + pref_subpr[i] = is_subpr[i] + pref_subpr[i - 1]; + } +} + +void answer(){ + cin >> n; + + int ret = n >= 5 ? pref_subpr[n - 2] : 0; + + cout << ret << endl; +} + +int main(){ + freopen("in.txt", "r", stdin); + freopen("out.txt", "w", stdout); + ios::sync_with_stdio(0); + cin.tie(0); + + precomp_primes(); + precomp_subprimes(); + + int t; + cin >> t; + + for(int i = 1; i <= t; i++){ + cout << "Case #" << i << ": "; + answer(); + } + + return 0; +} diff --git a/c++ sol/hackercup/2024/round1/C/sol b/c++ sol/hackercup/2024/round1/C/sol new file mode 100755 index 0000000..55fdd00 Binary files /dev/null and b/c++ sol/hackercup/2024/round1/C/sol differ diff --git a/c++ sol/hackercup/2024/round1/C/sol.cpp b/c++ sol/hackercup/2024/round1/C/sol.cpp new file mode 100644 index 0000000..3dd26dc --- /dev/null +++ b/c++ sol/hackercup/2024/round1/C/sol.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +#include +using namespace std; +#define endl '\n' +#define ll long long +#define pi pair +#define f first +#define s second + +const int mod = 998244353; +ll n, m, k; //W, G, L + +ll exp_move_left(){ + return (1 + 2 * k) % mod; +} + +void answer(){ + cin >> n >> m >> k; + + ll ret = ((mod + (n - m) % mod) % mod) * exp_move_left() % mod; + + cout << ret << endl; +} + +int main(){ + freopen("in.txt", "r", stdin); + freopen("out.txt", "w", stdout); + ios::sync_with_stdio(0); + cin.tie(0); + cout << fixed << setprecision(7); + + int t; + cin >> t; + + for(int i = 1; i <= t; i++){ + cout << "Case #" << i << ": "; + answer(); + } + + return 0; +} diff --git a/c++ sol/hackercup/2024/round1/C/substantial_losses_input.zip b/c++ sol/hackercup/2024/round1/C/substantial_losses_input.zip new file mode 100644 index 0000000..8264753 Binary files /dev/null and b/c++ sol/hackercup/2024/round1/C/substantial_losses_input.zip differ diff --git a/c++ sol/hackercup/2024/round1/D/sol b/c++ sol/hackercup/2024/round1/D/sol new file mode 100755 index 0000000..2af5fa5 Binary files /dev/null and b/c++ sol/hackercup/2024/round1/D/sol differ diff --git a/c++ sol/hackercup/2024/round1/D/sol.cpp b/c++ sol/hackercup/2024/round1/D/sol.cpp new file mode 100644 index 0000000..b718a0d --- /dev/null +++ b/c++ sol/hackercup/2024/round1/D/sol.cpp @@ -0,0 +1,119 @@ +#include +#include +#include +#include +using namespace std; +#define endl '\n' +#define ll long long +#define pi pair +#define f first +#define s second + +const int mod = 998244353; +const int mxn = 100001, w = 10; +int n, k; +int a[mxn]; +pi dp[mxn][w][2]; //{clamp, mod} +string s; +vector v; + +pi operator+(pi x, pi y){ + return {min(mod, x.f + y.f), (x.s + y.s) % mod}; +} + +bool valid_num(int x){ + return x >= 1 && x <= 26; +} + +void compute_dp(){ + for(int j = 0; j < w; j++){ + dp[n][j][0] = dp[n][j][1] = {0, 0}; + } + + dp[n][0][1] = {1, 1}; + for(int i = n - 1; ~i; i--) + for(int j = 0; j < w; j++){ + dp[i][j][0] = dp[i][j][1] = {0, 0}; + for(int l = 0; l < w; l++){ + dp[i][j][0] = dp[i][j][0] + dp[i + 1][l][1]; + if(valid_num(j)){ + dp[i][j][1] + dp[i][j][1] + dp[i + 1][l][1]; + } + if(valid_num(j * w + l)){ + dp[i][j][1] = dp[i][j][1] + dp[i + 1][l][0]; + } + } + } +} + +void compute_kth(){ + int cur[w][2], old_cur[w][2]; + for(int j = 0; j < w; j++){ + cur[j][0] = 0; + cur[j][1] = 1; + } + + int z = 0; + for(int i = 0, prev_dig = 0, fin_state = 1; i < n; i++){ + for(int j = 0; j < w; j++){ + int zz = 0; + for(int x = 0; x < 2; x++){ + zz = min((ll)mod, zz + (ll)cur[j][x] * dp[i][j][x].f); + } + + if(z + zz > k){ + v.push_back(j); + + memcpy(old_cur, cur, sizeof(cur)); + memset(cur, 0, sizeof(cur)); + for(int l = 0; l < w; l++){ + cur[l][1] += old_cur[j][0]; + if(valid_num(j)){ + cur[l][1] += old_cur[j][1]; + } + if(valid_num(j * w + l)){ + cur[l][1] += old_cur[j][0]; + } + } + break; + } + + z += zz; + } + } +} + +void answer(){ + cin >> s >> k; + n = s.size(), k--; + + for(int i = 0; i < n; i++){ + a[i] = s[i] - '0'; + } + + compute_dp(); + compute_kth(); + + int ret_cnt = 0; + for(int j = 0; j < w; j++) (ret_cnt += dp[0][j][1].s) %= mod; + + for(int i : v) cout << i; + cout << " " << ret_cnt << endl; +} + +int main(){ + freopen("in.txt", "r", stdin); + freopen("out.txt", "w", stdout); + ios::sync_with_stdio(0); + cin.tie(0); + + int t; + cin >> t; + + for(int i = 1; i <= t; i++){ + cout << "Case #" << i << ": "; + answer(); + } + + return 0; +}