Skip to content

Commit

Permalink
20240603 feat: Wangggong 0527 / 0531 / 0601 submissions (Yawn-Sean#3169)
Browse files Browse the repository at this point in the history
* feat: 0527

* feat: 0601

* feat: 0531
  • Loading branch information
wangggong authored Jun 4, 2024
1 parent 034691f commit 707907e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <iostream>
#include <algorithm>

typedef long long ll;
const ll N = 5000;
const ll MOD = 998244353;
ll n, a[N + 10], U[N + 10], ans, cur_sum;

int main() {
U[0] = 1;
scanf("%lld", &n); for (ll i = 0; i < n; i++)
scanf("%lld", a + i);
std::sort(a, a + n);
for (ll i = 0; i < n; i++) {
for (ll j = cur_sum; j >= 0; j--) {
ans += U[j] * std::max((j + a[i] + 1) / 2, a[i]), ans %= MOD, U[j + a[i]] += U[j], U[j + a[i]] %= MOD;
}
cur_sum += a[i];
}
printf("%lld", ans);
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 参考: https://github.com/Yawn-Sean/Daily_CF_Problems/blob/main/daily_problems/2024/05/0531/solution/cf1671d.md
//
// 完全看不懂的贪心...
#include <iostream>
#include <algorithm>

typedef long long ll;
const ll N = 2e5;
ll t, n, x, a[N + 10];

int main() {
scanf("%lld", &t); while (t--) {
scanf("%lld%lld", &n, &x); for (ll i = 0; i < n; i++)
scanf("%lld", a + i);
ll ans = 0;
for (ll i = 1; i < n; i++)
ans += std::abs(a[i] - a[i - 1]);
ans += std::min(std::min(a[0], a[n - 1]) - 1, 2 * *std::min_element(a, a + n) - 2);
ans += std::max(std::min(x - std::max(a[0], a[n - 1]), 2 * x - 2 * *std::max_element(a, a + n)), 0ll);
printf("%lld\n", ans);
}
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <iostream>
#include <cstring>

typedef long long ll;
const ll N = 1000;
const ll MOD = 1e9 + 7;
ll t, n, k, f[N + 10][N + 10];

ll dfs(ll n, ll k) {
memset(f, 0, sizeof f);
for (ll j = 1; j <= k; j++) {
f[0][j] = 1;
for (ll i = 1; i <= n; i++)
f[i][j] = (f[i - 1][j] + f[n - i][j - 1]) % MOD;
}
return f[n][k];
}

int main() {
scanf("%lld", &t); while (t--)
scanf("%lld%lld", &n, &k), printf("%lld\n", dfs(n, k));
return 0;
}

0 comments on commit 707907e

Please sign in to comment.