Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #ifndef ONLINE_JUDGE
- #include "./debug.h"
- #else
- #define debug(...)
- #endif
- using namespace std;
- #define int long long
- const int inf = 1e18;
- const int N = 1e5 + 5;
- const int mod = 1e9 + 7;
- const vector<char> chars = {'#', '$', '%', '@', '&'};
- void solve() {
- map<char, int> ids;
- for (int i = 0; i < 5; i++) {
- ids[chars[i]] = i;
- }
- int n;
- cin >> n;
- vector<pair<string, int>> arr(n + 1);
- for (int i = 1; i <= n; i++) {
- cin >> arr[i].first >> arr[i].second;
- }
- vector<vector<int>> dp(n + 1, vector<int>(32, inf));
- for (int i = 0; i <= n; i++) {
- dp[i][0] = 0;
- }
- for (int i = 1; i <= n; i++) {
- int mask = 0;
- for (char c : arr[i].first) {
- mask |= (1 << ids[c]);
- }
- for (int j = 0; j < 32; j++) {
- dp[i][j] = dp[i - 1][j];
- }
- for (int j = 0; j < 32; j++) {
- dp[i][j | mask] =
- min(min(dp[i][j | mask], (dp[i - 1][j]) + arr[i].second),
- dp[i - 1][j | mask]);
- }
- }
- int res = inf;
- for (int i = 1; i <= n; i++) {
- res = min(res, dp[i][31]);
- }
- cout << (res == inf ? -1 : res) << "\n";
- }
- signed main() {
- #ifndef ONLINE_JUDGE
- freopen("input.out", "r", stdin);
- freopen("output.out", "w", stdout);
- freopen("error.out", "w", stderr);
- #endif
- int T = 1;
- // cin >> T;
- for (int t = 1; t <= T; t++) {
- // cout << "Case #" << t << ": ";
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment