diff --git a/USACO/2021.12-Bronze/1/1.cpp b/USACO/2021.12-Bronze/1/1.cpp new file mode 100644 index 00000000..56c12759 --- /dev/null +++ b/USACO/2021.12-Bronze/1/1.cpp @@ -0,0 +1,40 @@ +#include +#include + +using std::cin; +using std::cout; +using std::endl; + +int n; +long long ans; +char c; +std::vector g, h; + +int main() { + std::ios::sync_with_stdio(false); + cin >> n; + g.push_back(0); + h.push_back(0); + for (int i = 1; i <= n; i++) { + cin >> c; + if (c == 'G') { + g.push_back(i); + } else { + h.push_back(i); + } + } + g.push_back(n + 1); + h.push_back(n + 1); + for (int i = 1; i < h.size() - 1; i++) { + ans += 1ll * (h[i] - h[i - 1]) * (h[i + 1] - h[i]) - 3; + if (h[i] == h[i - 1] + 1) ans++; + if (h[i] == h[i + 1] - 1) ans++; + } + for (int i = 1; i < g.size() - 1; i++) { + ans += 1ll * (g[i] - g[i - 1]) * (g[i + 1] - g[i]) - 3; + if (g[i] == g[i - 1] + 1) ans++; + if (g[i] == g[i + 1] - 1) ans++; + } + cout << ans << endl; + return 0; +} diff --git a/USACO/2021.12-Bronze/2/2.cpp b/USACO/2021.12-Bronze/2/2.cpp new file mode 100644 index 00000000..4da81633 --- /dev/null +++ b/USACO/2021.12-Bronze/2/2.cpp @@ -0,0 +1,27 @@ +#include + +using std::cin; +using std::cout; +using std::endl; + +int n, x, a[100005], b[100005], ans; + +int main() { + std::ios::sync_with_stdio(false); + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + for (int i = 1; i <= n; i++) { + cin >> x; + a[i] -= x; + if (a[i] < 0) { + b[i] = -a[i]; + a[i] = 0; + } + if (a[i] > a[i - 1]) ans += a[i] - a[i - 1]; + if (b[i] > b[i - 1]) ans += b[i] - b[i - 1]; + } + cout << ans << endl; + return 0; +} diff --git a/USACO/2021.12-Bronze/3/3.cpp b/USACO/2021.12-Bronze/3/3.cpp new file mode 100644 index 00000000..7c2a9e02 --- /dev/null +++ b/USACO/2021.12-Bronze/3/3.cpp @@ -0,0 +1,34 @@ +#include +#include + +using std::cin; +using std::cout; +using std::endl; + +int t, n, k, ans; +std::string g[55]; + +void dfs(int x, int y, int cnt, int from) { + if (x < 0 || x >= n || y < 0 || y > n || cnt > k || g[x][y] == 'H') return; + if (x == n - 1 && y == n - 1) { + ans++; + return; + } + dfs(x + 1, y, cnt + (from == 2), 1); + dfs(x, y + 1, cnt + (from == 1), 2); +} + +int main() { + std::ios::sync_with_stdio(false); + cin >> t; + while (t--) { + ans = 0; + cin >> n >> k; + for (int i = 0; i < n; i++) { + cin >> g[i]; + } + dfs(0, 0, 0, 0); + cout << ans << endl; + } + return 0; +}